【问题标题】:Best way to run background "algrothim" which updates widgets Qt运行更新小部件Qt的后台“算法”的最佳方式
【发布时间】:2013-12-12 15:46:14
【问题描述】:

所以我有一个使用 GridLayout 创建的 GUI 应用程序。我制作了一堆 QLineEdit 小部件,这些小部件需要在新值出现时不断更新。最好和最有效的方法是什么?似乎是一个愚蠢的问题,但我在网上做了一些研究,似乎找不到最好和最有效的解决方案。提前致谢。

我尝试做 QTimer,它可以编译...但由于某种原因似乎永远不会超时(我在 run() 中有调试打印语句,它永远不会被打印。

    time = new QLineEdit();
    operationMode->setFixedWidth(150);
    layout->addWidget(time, 4,7);

    /*Test*/
    qDebug() << "Here 1";
    QTimer* timer = new QTimer(this);
    timer->setSingleShot(false);
    timer->setInterval(10 * 100); // 1 seconds
    connect(timer, SIGNAL(timeout()), this, SLOT(run()));

    setLayout(layout);
}


void MainWindow::run(void)
{
    qDebug() << "Here 2";
    time->setText(QTime::currentTime().toString());
    qDebug() << "Here 3";
        //qApp->processEvents();

}

【问题讨论】:

  • 研究多线程。
  • 你标题中“算法”的拼写错误有什么意义吗?

标签: c++ qt qlineedit


【解决方案1】:

让我的 QTimer 工作,显然我需要运行 timer->start(1000)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 2016-08-10
    相关资源
    最近更新 更多