Results 1 to 18 of 18

Thread: create a Class inherits from two QObject subclasses

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: create a Class inherits from two QObject subclasses

    So most likely mThread is an uninitialized pointer which points to 0xcdcdcdd1. Don't you think you should have
    Qt Code:
    1. mThread = new QThread(this);
    To copy to clipboard, switch view to plain text mode 
    somewhere?
    J-P Nurmi

  2. #2
    Join Date
    Jul 2007
    Posts
    166
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    25
    Thanked 1 Time in 1 Post

    Default Re: create a Class inherits from two QObject subclasses

    Hi
    When I give the command in my constructor
    Qt Code:
    1. mThread = new QThread(this);
    To copy to clipboard, switch view to plain text mode 

    then Qt return an error like this

    .\Test.cpp(70) : error C2259: 'QThread' : cannot instantiate abstract class
    due to following members:
    'void QThread::run(void)' : is abstract
    c:\qt\4.3.0\include\qtcore\qthread.h(87) : see declaration of 'QThread::run'
    Last edited by jpn; 31st December 2007 at 10:43. Reason: missing [code] tags

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: create a Class inherits from two QObject subclasses

    Ahh, indeed. QThread will be non-abstract in Qt 4.4 but until that you will have to implement QThread::run().
    J-P Nurmi

  4. #4
    Join Date
    Jul 2007
    Posts
    166
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    25
    Thanked 1 Time in 1 Post

    Default Re: create a Class inherits from two QObject subclasses

    Hi,
    In my code I had implement the run(). Please see the code , which one i previous declare.

    in .h file
    Qt Code:
    1. virtual void run();
    To copy to clipboard, switch view to plain text mode 

    and in .cpp file

    Qt Code:
    1. void CTest::run() {
    2. .....
    3. .....
    4. }
    To copy to clipboard, switch view to plain text mode 

    is it correct?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: create a Class inherits from two QObject subclasses

    A friendly advise would be to learn C++ before trying to use a comprehensive toolkit written in C++. Using Qt sure requires some knowledge of C++.

    What you have shown above declares a method "virtual void run()" in a class which has QThread pointer as a member. That's not at all same than implementing QThread::run().

    Notice the difference between:
    Qt Code:
    1. class Foo : public QObject
    2. {
    3. protected:
    4. virtual void run() { ... }
    5.  
    6. QThread* mThread;
    7. };
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. class MyThread : public QThread
    2. {
    3. protected:
    4. virtual void run() { ... }
    5. };
    6.  
    7. class Bar : public QObject
    8. {
    9. protected:
    10. MyThread* mThread;
    11. };
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    sabeesh (1st January 2008)

  7. #6
    Join Date
    Jul 2007
    Posts
    166
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    25
    Thanked 1 Time in 1 Post

    Default Re: create a Class inherits from two QObject subclasses

    Hi,
    Its my mistake. Sorry.

    I create a class like this
    Qt Code:
    1. class MyThread : public QThread
    2. {
    3.  
    4. protected:
    5. virtual void run(){
    6. while(true){
    7. qDebug()<<"Run";
    8. }
    9. }
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 

    and in .h file
    Qt Code:
    1. QThread *mThread;
    To copy to clipboard, switch view to plain text mode 

    and give the command in my constructor like this

    Qt Code:
    1. mThread = new QThread(this);
    To copy to clipboard, switch view to plain text mode 


    but the error is like this

    Qt Code:
    1. .\Test.cpp(70) : error C2259: 'QThread' : cannot instantiate abstract class
    2. due to following members:
    3. 'void QThread::run(void)' : is abstract
    4. c:\qt\4.3.0\include\qtcore\qthread.h(87) : see declaration of 'QThread::run'
    To copy to clipboard, switch view to plain text mode 


    Please help me

  8. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: create a Class inherits from two QObject subclasses

    QThread is abstract. You must instantiate your QThread subclass:
    Qt Code:
    1. mThread = new MyThread(this);
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to marcel for this useful post:

    sabeesh (1st January 2008)

  10. #8
    Join Date
    Jul 2007
    Posts
    166
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    25
    Thanked 1 Time in 1 Post

    Default Re: create a Class inherits from two QObject subclasses

    Hi,
    Ohhhh, It's my mistake. Sorry.
    Thankyou for your help

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
  •  
Qt is a trademark of The Qt Company.