• <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 天下 閱讀(1101) 評論(0)  編輯 收藏 引用 所屬分類: Linux編程QT

            <2011年9月>
            28293031123
            45678910
            11121314151617
            18192021222324
            2526272829301
            2345678

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            亚洲国产精品久久久天堂| 国产精品成人99久久久久 | 91麻豆国产精品91久久久| 国产精久久一区二区三区 | 久久精品九九亚洲精品天堂| 亚洲人成伊人成综合网久久久| 久久精品中文字幕一区| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 久久福利片| 久久久久久久综合日本| 久久精品国产一区二区电影| 久久福利片| 久久精品国产免费观看三人同眠| 久久久久亚洲国产| 久久久一本精品99久久精品66| 久久精品国产亚洲AV无码麻豆 | 亚洲人成无码www久久久| 一本色道久久综合| 久久亚洲日韩精品一区二区三区| 久久A级毛片免费观看| 国产精品久久网| 久久精品免费大片国产大片| 噜噜噜色噜噜噜久久| 久久婷婷五月综合97色一本一本| 久久精品蜜芽亚洲国产AV| 久久国产精品波多野结衣AV| 伊人 久久 精品| 国产产无码乱码精品久久鸭| 精品久久久久久无码中文字幕| 久久综合偷偷噜噜噜色| 久久综合丁香激情久久| 亚洲欧洲久久久精品| 2021精品国产综合久久| 美女久久久久久| 久久被窝电影亚洲爽爽爽| 思思久久99热只有频精品66| 久久久久久免费一区二区三区| 久久精品国产精品亜洲毛片| 成人综合伊人五月婷久久| 无码人妻少妇久久中文字幕| 精品久久久久久久|