PDA

View Full Version : Is it possible to create a QThread without inheriting ?



probine
23rd March 2006, 21:45
I would like to create a QThread by just including "# include <QThread>" and ofcourse giving an statement as:

QThread* myThread;
myThread = new QThread();

This results in this error:

server.cpp: In member function 'void Server::newConnection()':
server.cpp:55: error: cannot allocate an object of abstract type 'QThread'
/usr/local/Trolltech/Qt-4.1.1/include/QtCore/qthread.h:38: note: because the following virtual functions are pure within 'QThread':
/usr/local/Trolltech/Qt-4.1.1/include/QtCore/qthread.h:86: note: virtual void QThread::run()
make: *** [server.o] Error 1


How can I create a QThread then ?

wysota
23rd March 2006, 21:47
You have to inherit to implement the run() method which is pure virtual (as the compiler already mentioned).

probine
23rd March 2006, 22:02
The documentation shows:
______________________________________
QThread::QThread ( QObject * parent = 0 )

Constructs a new thread with the given parent. The thread does not begin executing until start() is called.

See also start().
_____________________________________


As I see it, I could create something like:

QThread* myThread = new QThread(this);

jacek
23rd March 2006, 22:04
As I see it, I could create something like:

QThread* myThread = new QThread(this);
And what would this thread do?

probine
23rd March 2006, 22:08
This thread should handle the client's connections - send and receive data.

wysota
23rd March 2006, 22:18
The documentation shows:
______________________________________
QThread::QThread ( QObject * parent = 0 )

Constructs a new thread with the given parent. The thread does not begin executing until start() is called.

See also start().
_____________________________________


As I see it, I could create something like:

QThread* myThread = new QThread(this);

You can't instantiate objects which have at least one virtual method abstract. There's nothing more to it. Besides, without a run() method the thread wouldn't do anything, as already mentioned in previous posts.

jacek
23rd March 2006, 22:51
This thread should handle the client's connections - send and receive data.
And how would you make it do all of this?