Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to create multiple windows in separated threads using Qt?



  • Hello

    I want to open multiple windows using multithread with one window one thread on single click.

    Please solve this.

    Thanks
    Zain



  • You cannot. All Qt GUI objects must reside in the main program thread.

    Multiple non-GUI worker threads can communicate with GUI objects in the main thread using the signals/slots mechanism.



  • Hello ChrisW67

    If it is not possible then please tell me another solution to create multiple webView on single click.



  • Threads are not required to have multiple windows. Something like:

    @
    void on_button_clicked() {
    QWebview *webView1 = new QWebView;
    webView1->setAttribute(Qt::WA_DeleteOnClose);
    webView1->load(QUrl("http://qt-project.org"));
    webView1->show();

    QWebview *webView2 = new QWebView;
    webView2->setAttribute(Qt::WA_DeleteOnClose);
    webView2->load(QUrl("http://google.com"));
    webView2->show();
    }
    @



  • Thanks ChrisW67

    Also I want to set time for each webView. After particular time webView should be closed.

    So will it be feasible to use the code you have provided?



  • Yes, using QTimer (in combination with QTime if necessary) in any number of ways.



  • Thanks ChristW67



  • Hello

    There is issue in when i am setting timer.

    I have used code as:

    timer->stop

    this give exception: "Exception at 0x61a3a53f, code: 0xc0000005: read access violation at: 0x0, flags=0x0"



  • The value of timer is null (0) or otherwise invalid, dereferencing a null pointer is bad.



  • I am unable to solve multhreading functionality to load video on multiple webview & set proxy for it for particular time.

    Please tell better solution for this.


Log in to reply