Results 1 to 7 of 7

Thread: Is it possible to create a QThread without inheriting ?

  1. #1
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Is it possible to create a QThread without inheriting ?

    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 ?

  2. The following user says thank you to probine for this useful post:

    incapacitant (23rd March 2006)

  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is it possible to create a QThread without inheriting ?

    You have to inherit to implement the run() method which is pure virtual (as the compiler already mentioned).

  4. #3
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to create a QThread without inheriting ?

    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);

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to create a QThread without inheriting ?

    Quote Originally Posted by probine
    As I see it, I could create something like:

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

  6. #5
    Join Date
    Jan 2006
    Posts
    185
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to create a QThread without inheriting ?

    This thread should handle the client's connections - send and receive data.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is it possible to create a QThread without inheriting ?

    Quote Originally Posted by probine
    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.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Is it possible to create a QThread without inheriting ?

    Quote Originally Posted by probine
    This thread should handle the client's connections - send and receive data.
    And how would you make it do all of this?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.