0

尝试根据 QTimer 触发的时间显示文本...

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    m_label1 = new QLabel("My Label not working", this);

    QTimer* timerDisplay = new QTimer(this);
    connect(timerDisplay, SIGNAL(Started()), this, SLOT(updateDisplay(this)));
    timerDisplay->start(10);

}


void updateDisplay(MainWindow* m_this)
{
    QString out;
    out = "hello";

    m_this->m_label1->setText("asdf");
}
4

1 回答 1

3
connect(timerDisplay, SIGNAL(Started()), this, SLOT(updateDisplay(this)));

这个说法不成立。而且您忽略了 Qt 在您的控制台上打印的消息。

问题是,您不能在这样的connect语句中传递变量。顺便说一句,为了什么?您可以thisupdateDisplay方法中使用而无需显式传递它!

于 2013-07-17T21:36:23.387 回答