Qt 6.11 is out! See what's new in the release
blog
Slot function pointer with arguments
-
I'm trying to use setText() in a slot on connect without using a lambda. Here's what I have:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); QApplication::connect(timeThread, &QThread::started, timer, &CustomTimer::start); QApplication::connect(timeThread, &QThread::finished, ui->timeLabel, &QLabel::setText("Done")); }I'm just unsure how to call the function if it has an argument. Any guidance is appreciated.
Thanks!
-
I'm trying to use setText() in a slot on connect without using a lambda. Here's what I have:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); QApplication::connect(timeThread, &QThread::started, timer, &CustomTimer::start); QApplication::connect(timeThread, &QThread::finished, ui->timeLabel, &QLabel::setText("Done")); }I'm just unsure how to call the function if it has an argument. Any guidance is appreciated.
Thanks!
@TheLumbee So create a slot:
*.h
private slots: void handle_finished();*.cpp
void MainWindow::handle_finished(){ ui->timeLabel->setText("Done"); }and the connection:
connect(timeThread, &QThread::finished, this, &MainWindow::handle_finished); -
Yeah, I didn't know if I needed to create a class to inherit from QLabel for that. Need to promote a label in designer but I wanted to make sure that was the simplest way.
Thanks for the quick response!