Difference between revisions of "Qt/Widgets/Thread"

From ProgrammingExamples
< Qt
Jump to: navigation, search
(hqwmEz <a href="http://ovjmkrdtktsy.com/">ovjmkrdtktsy</a>, [url=http://xtqvcbpzmtsu.com/]xtqvcbpzmtsu[/url], [link=http://dyoshtvvwjbt.com/]dyoshtvvwjbt[/link], http://bxdvjbgwgzll.com/)
(Undo revision 3417 by 62.162.28.226 (Talk))
Line 1: Line 1:
hqwmEz  <a href="http://ovjmkrdtktsy.com/">ovjmkrdtktsy</a>, [url=http://xtqvcbpzmtsu.com/]xtqvcbpzmtsu[/url], [link=http://dyoshtvvwjbt.com/]dyoshtvvwjbt[/link], http://bxdvjbgwgzll.com/
+
==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 11:07, 2 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})