Important: Please read the Qt Code of Conduct -

Multiple threads to open the same url in console application

  • Hi ,
    I am new to this great QT environment and working on a demo application.
    Basically I need to open urls in the console application.

    1. Once the url is finished loading , I need to sleep / wait that thread for a few seconds
    2. Meanwhile I will start another thread and open a different url and do the same kind of thing.

    I guess there are two approaches to accomplish this task 1)QteventLoop 2)QThread , I chose QThread.

    My code for main.cpp is

    @int main(int argc, char *argv[])
    QApplication app(argc, argv);

    Thread tr ; //Thread object
    QWebSettings *webSettings = QWebSettings::globalSettings();
    webSettings->setAttribute(QWebSettings::AutoLoadImages, true);
    webSettings->setAttribute(QWebSettings::JavascriptEnabled, true);
    Html5ApplicationViewer *viewer = new Html5ApplicationViewer();

    //where to run the created thread ? as works bt doesn't serve the applicaion purpose
    return app.exec();


    I have created a class for thread
    @class Thread: public QThread
    void run();
    void stop();
    volatile bool stopped;

    std::cout<<"creating the object";
    stopped = false;

    void Thread::run()
    std::cout << "running " << std::endl;

    stopped = false;


    void Thread::stop()
    stopped = true;

    std::cout<<"stopped" << std::endl;


    The code runs without error but How can I open the set of urls in the same application as in the end it returns app.exec() .

    Hope I was clear to explain my problem.

    Any help would be appreciated,

  • Can anybody help me with this ?

  • Why do you need a different thread? you can use QTimer.
    By the way. Merely instantiating Thread object doesnt start the thread, one has to invoke start() method on it.

  • Also your QThread subclass implementation of the run function is missing the exec() call, so your Thread has no running eventloop. Have a look at "this link": .

    In case the Html5ApplicationViewer instance is using any Gui class like e.g. QWebView you won't be able to run instances of this class in any other thread but the main thread. If that is what you wanted to do.

Log in to reply