"Go" QT Multi-threaded interface---update Qprogressbar in Qthread

Source: Internet
Author: User

#include <QApplication> #include <QThread> #include <QMainWindow> #include <qprogressbar>#        Include <qpushbutton>class Renderthread:public qthread{q_objectsignals:void notify (int);p ublic:        Renderthread (Qobject *parent = 0): Qthread (parent) {};        void Test () {start (highestpriority);                };p rotected:void Run () {int i = 0;                        while (i<101) {msleep (50);                        i++;                Emit notify (i); }        };};         Class Mainwindow:public qmainwindow{Q_objectpublic:mainwindow (qwidget *parent = 0) {Resize (600, 400);        Centralwidget = new Qwidget (this);        ProgressBar = new Qprogressbar (centralwidget);        Progressbar->setgeometry (Qrect (130, 180, 321, 23));        Progressbar->setvalue (0);   pushbutton = new Qpushbutton ("Test", centralwidget);     Pushbutton->setgeometry (Qrect (110, 100, 75, 23));        Qobject::connect (pushbutton, SIGNAL (clicked ()), this, SLOT (onclicked ()));    This->setcentralwidget (Centralwidget);    };    ~mainwindow () {};p Rivate:qprogressbar *progressbar;    Qpushbutton *pushbutton;    Qwidget *centralwidget; Renderthread render;public slots:void onclicked () {Connect (&render,signal (notify (int)), This,slot (Onnoti        FY (int)));        Render.test ();    };        void onnotify (int i) {progressbar->setvalue (i); };};    #include "Test.moc" int main (int argc,char* argv[]) {qapplication app (ARGC,ARGV);    MainWindow window;    Window.show (); return app.exec ();}

http://blog.csdn.net/tingsking18/article/details/5096172

"Go" QT Multi-threaded interface---update Qprogressbar in Qthread

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.