• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            qt對話框+線程小試

            //thread.h
            #pragma once
            #define QT3_SUPPORT
            #include 
            <iostream>
            #include 
            <cstdio>
            #include 
            <unistd.h>
            #include 
            <Qt/qapplication.h>
            #include 
            <Qt/qpushbutton.h>
            #include 
            <qmessagebox.h> 
            #include 
            <Qt/qdialog.h>
            #include 
            <Qt/qthread.h>
            #include 
            <QString>


            template
            <typename T>
            class Thread : public QThread
            {
            public:
                Thread();
                
            ~Thread();
                
            void run();
                
            void setTObj(T* pobj);
            public:
                
            int flag;
                unsigned 
            int pos;
                T
            * pTObj;
            };


            template
            <typename T>
            Thread
            <T>::Thread()
            {
                flag 
            = 1;
                pos 
            =0;
            }

            template
            <typename T>
            Thread
            <T>::~Thread()
            {

            }

            template
            <typename T>
            void Thread<T>::run()
            {
                
            //QMessageBox::information( NULL, "Application name","Started.\n");
                QString strText;
                
            while(flag)
                {
                    strText.sprintf(
            "flag:%d",pos);
                    pTObj
            ->setWindowTitle(strText);
                    pos
            ++;
                    QThread::msleep(
            500);
                }
            }

            template
            <typename T>
            void Thread<T>::setTObj(T* pobj)
            {
                pTObj 
            = pobj;
            }

            //ProcessDialog.h
            #pragma once
            #define QT3_SUPPORT

            #include 
            <iostream>
            #include 
            <cstdio>
            #include 
            <unistd.h>
            #include 
            <Qt/qapplication.h>
            #include 
            <Qt/qpushbutton.h>
            #include 
            <qmessagebox.h> 
            #include 
            <Qt/qdialog.h>
            #include 
            <Qt/qthread.h>
            #include 
            <QString>
            #include 
            "Thread.h"

            class ProcessDialog :public QDialog 
            {
                Q_OBJECT
            public:
                ProcessDialog(QWidget
            * parent=0)
                    :btnStop(
            "Stop",this)
                    ,btnWork(
            "Work",this)
                {
                    btnStop.setGeometry( 
            62407530 );
                    btnWork.setGeometry( 
            162,1407530 );

                    threadA.setTObj(
            this);

                    connect(
            &btnWork,SIGNAL( clicked()),this,SLOT(start()) );
                    connect(
            &btnStop,SIGNAL( clicked()),this,SLOT(stop()) );
                }

            public:
                QPushButton btnStop;
                QPushButton btnWork;
                
            private slots:
                    
            void start()
                    {
                        btnWork.setText(
            "Working");
                        threadA.start();
                        threadA.flag 
            = 1;
                    }
                    
            void stop()
                    {
                        btnWork.setText(
            "Work");
                        threadA.flag 
            = 0;
                        
            //threadA.pos  = 0;
                    }

            private:
                Thread
            <ProcessDialog> threadA;    
            };


            //main.cpp
            #define QT3_SUPPORT
            #include 
            <iostream>
            #include 
            <cstdio>
            #include 
            <unistd.h>
            #include 
            <Qt/qapplication.h>
            #include 
            <Qt/qpushbutton.h>
            #include 
            <qmessagebox.h> 
            #include 
            <Qt/qdialog.h>
            #include 
            <Qt/qthread.h>
            #include 
            <QString>
            #include 
            "Thread.h"
            #include 
            "ProcessDialog.h"

            int main( int argc, char **argv )
            {
                QApplication app( argc, argv );
                ProcessDialog dlg;
                app.setMainWidget( 
            &dlg );
                dlg.resize(
            640,480);
                dlg.setModal(
            true);
                dlg.exec();
                
            return app.exec();
            }

            posted on 2011-09-22 10:24 天下 閱讀(1106) 評論(0)  編輯 收藏 引用 所屬分類: Linux編程QT

            <2012年6月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            1234567

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            亚洲国产精品久久久久婷婷老年| 婷婷综合久久中文字幕蜜桃三电影| 久久精品国产亚洲AV麻豆网站| 久久精品国产亚洲AV香蕉| 久久久久亚洲AV无码麻豆| 中文字幕一区二区三区久久网站| 久久久久国产精品麻豆AR影院| 亚洲伊人久久成综合人影院 | 麻豆精品久久久一区二区| 91精品国产91久久久久久青草| 久久国产精品免费一区| 日本强好片久久久久久AAA | 久久国产香蕉一区精品| 午夜久久久久久禁播电影 | 无码超乳爆乳中文字幕久久 | 亚洲欧洲久久av| 91精品国产91热久久久久福利 | 日韩中文久久| 久久国产免费观看精品| 伊人久久大香线蕉综合Av| 久久精品国产精品亚洲| 久久国产精品成人免费| 国内精品久久久久影院一蜜桃| 性欧美大战久久久久久久| 亚洲欧美精品伊人久久| 国产精品久久久福利| 婷婷久久香蕉五月综合加勒比| 久久人人爽人人爽人人爽| 久久国产V一级毛多内射| 国产成人精品久久综合| 99国产精品久久| 狠狠久久亚洲欧美专区| 99久久er这里只有精品18| 久久精品国产第一区二区三区| 久久久国产精华液| 亚洲中文字幕无码一久久区| 久久久久久精品久久久久| 囯产极品美女高潮无套久久久 | 久久精品视屏| 综合久久精品色| 久久婷婷色综合一区二区|