Difference between revisions of "Qt/Widgets/Thread"
From ProgrammingExamples
< Qt
(→Thread.cxx) |
Daviddoria (Talk | contribs) (Undo revision 3655 by 200.251.58.190 (Talk)) |
||
Line 1: | Line 1: | ||
− | + | ==Thread.cxx== | |
+ | <source lang="cpp"> | ||
+ | #include <QThread> | ||
+ | |||
+ | class MyThread : public QThread | ||
+ | { | ||
+ | |||
+ | public: | ||
+ | |||
+ | virtual void run(); | ||
+ | }; | ||
+ | |||
+ | void MyThread::run() | ||
+ | { | ||
+ | for( int count = 0; count < 20; count++ ) | ||
+ | { | ||
+ | sleep( 1 ); | ||
+ | qDebug( "Ping!" ); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | MyThread a; | ||
+ | MyThread b; | ||
+ | a.start(); | ||
+ | b.start(); | ||
+ | a.wait(); | ||
+ | b.wait(); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </source> | ||
==CMakeLists.txt== | ==CMakeLists.txt== |
Revision as of 08:16, 4 March 2011
Thread.cxx
#include <QThread> class MyThread : public QThread { public: virtual void run(); }; void MyThread::run() { for( int count = 0; count < 20; count++ ) { sleep( 1 ); qDebug( "Ping!" ); } } int main() { MyThread a; MyThread b; a.start(); b.start(); a.wait(); b.wait(); return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(Thread) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ADD_EXECUTABLE(Thread Thread.cpp)# ${MOCSrcs} ${UISrcs}) TARGET_LINK_LIBRARIES(Thread ${QT_LIBRARIES})