Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Behind the Scenes
  3. Qt.io webservices
  4. Multiple threads to open the same url in console application
Forum Updated to NodeBB v4.3 + New Features

Multiple threads to open the same url in console application

Scheduled Pinned Locked Moved Qt.io webservices
4 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shrikant
    wrote on 29 Jul 2013, 09:37 last edited by
    #1

    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);
    webSettings->setAttribute(QWebSettings::DeveloperExtrasEnabled,true);
    
    
    Html5ApplicationViewer *viewer = new Html5ApplicationViewer();
    
    viewer->setOrientation(Html5ApplicationViewer::ScreenOrientationAuto);
    
    viewer->showExpanded();
    
    viewer->loadUrl(QUrl(QLatin1String("http://google.com")));--
    

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

    }@

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

    Thread::Thread()
    {
    std::cout<<"creating the object";
    stopped = false;
    }

    void Thread::run()
    {
    while(!stopped)
    {
    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,
    Shrikant

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Shrikant
      wrote on 14 Aug 2013, 10:04 last edited by
      #2

      Can anybody help me with this ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shrikantd
        wrote on 28 Aug 2013, 21:29 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on 29 Aug 2013, 07:00 last edited by
          #4

          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":http://qt-project.org/wiki/QThreads_general_usage .

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved