Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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()
    {
      scanfile()
    }
    

    main.cpp
    code:

    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.
    w.resize(800,400);
    w.show();
    bool endapp=a.exec();
    thread.stop();
    return endapp;
    

    I want qwtthread to execute first and complete it the task for 3 seconds and after this mainwindow obj.show 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

    Hi,

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


Log in to reply