Important: Please read the Qt Code of Conduct -

How to execute a Thread(QwtSamplingThread) for sometime and making the GUI(mainwindow) wait for 3 seconds?.

  • Hi Guys,
    I have created class filethread which inherits the QwtSamplingThread for filereading it executes one function in run()
    filethread.cpp code:

    void Filethread::run()


    int main()
    QApplication a(argc,argv);
    FileThread thread;
    thread.start();//this qwt thread I want it to complete the task for 3 seconds and then the compiler to star the mainwindow object which is GUI thread because this will get the data vector from the Filethread object.
    MainWindow w;//this should be started after the filethread object complition.
    bool endapp=a.exec();
    return endapp;

    I want qwtthread to execute first and complete it the task for 3 seconds and after this mainwindow should execute, how to do this?
    how to do this, please help.

  • I think you can emit a signal when the qwt thread complete it's task.
    And connect the signal to a slot of mainwindow.
    Then let the mainwindow to do the things.

  • I would like to implement this and see. Thanks for the idea.

  • Lifetime Qt Champion


    The quick and silly method: QTimer::singleShot(3000, &w, &QMainWindow::show);

Log in to reply