c++ - 错误: no matching function for call to 'QLabel::text(QString&)'

标签 c++ windows qt

我尝试制作文件浏览器,但出了什么问题

这是我的mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_4_clicked()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                                                 "",
                                                 tr("Files (*.mp3 *.ogg)"));
    ui->label->text(fileName);
}

错误:

C:\Users\account\eka\mainwindow.cpp:24: error: no matching function for call to 'QLabel::text(QString&)'
     ui->label->text(fileName);
                             ^

我刚刚开始使用 Qt,请帮助我。

最佳答案

使用 setText() 而不是 text()。 text() 是一个 setter/getter

ui->label->setText(文件名);

关于c++ - 错误: no matching function for call to 'QLabel::text(QString&)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26742357/

相关文章:

C++ Blowfish 哈希实现

c++ - 如何压缩备份日志文件?

c++ - 安全回调提供程序(SFINAE、std::forward 和重载解析)

c++ - 查找未使用的包含标题的工具?

python - 使用 win32file.ReadFile 从管道获取输出的正确方法是什么?

c# - 如何让我的 Windows 服务以特定的时间间隔运行?

c++ - 网络回复后Qt更新

c - 如何以编程方式设置文件的修改时间?

c++ - 通过 QTimer 和 QTcpSocket 正确使用 QThread 和 moveToThread

qt - 在 Ubuntu 21.04 上安装 Qt5