Results 1 to 7 of 7

Thread: Why this error?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Why this error?

    QLCDNumber is already a QObject so you don't require the Q_OBJECT macro in your derived class definition. The linker is getting confused looking in the wrong place for the tables used to support QObjects.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    116
    Thanked 42 Times in 41 Posts

    Default Re: Why this error?

    but if he removes Q_OBJECT the connect will be failed ... at console he will receive
    Object::connect: No such slot QLCDNumber::increase()
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Why this error?

    MOC isn't being run. If your using the QtCreator IDE, then use Build->Run QMake. Leave the Q_OBJECT in there, it's required.

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    116
    Thanked 42 Times in 41 Posts

    Default Re: Why this error?

    but in normal qt compilation ...

    he should include "main.moc" in his main file

    code will be

    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. class LCDCounter : public QLCDNumber{
    5. Q_OBJECT
    6.  
    7. private:
    8. int counter;
    9. public:
    10. LCDCounter(QWidget *parent = 0)
    11. :QLCDNumber(parent)
    12. {
    13. counter = 0;
    14. setSegmentStyle(QLCDNumber::Filled);
    15. display(0);
    16. }
    17. public slots:
    18. void increase()
    19. {
    20. display(counter++);
    21.  
    22. }
    23.  
    24. };
    25. class MyWidget : public QWidget
    26. {
    27. Q_OBJECT
    28. public:
    29. MyWidget()
    30. : QWidget(0)
    31. {
    32. clickMe = new QPushButton("Click me!");
    33. counter = new LCDCounter();
    34. connect(clickMe,SIGNAL(clicked()),counter,SLOT(increase()));
    35. QVBoxLayout *boxLayout = new QVBoxLayout;
    36. boxLayout->addWidget(clickMe);
    37. boxLayout->addWidget(counter);
    38. setLayout(boxLayout);
    39.  
    40. }
    41.  
    42.  
    43. private:
    44. QPushButton *clickMe;
    45. LCDCounter *counter;
    46. };
    47.  
    48.  
    49. #include "main.moc"
    50.  
    51. int main(int argc, char *argv[])
    52. {
    53. QApplication a(argc, argv);
    54. MyWidget w;
    55. w.show();
    56. return a.exec();
    57. }
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Jan 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: Why this error?

    Hi all and many thanks for your responses.

    MOC isn't being run. If your using the QtCreator IDE, then use Build->Run QMake. Leave the Q_OBJECT in there, it's required.
    I forgot to say that I'm working with Visual Studio 2008 and QT 4.6.
    With the Visual Studio add-in, the project created with the assistant doesn't includes the moc file as wagmare says. I'll try the changes you are suggesting.

    Thanks

  6. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    116
    Thanked 42 Times in 41 Posts

    Default Re: Why this error?

    include "main.moc" above main and macro Q_OBJECT in MyWidget class .. your code is working fine ...
    "Behind every great fortune lies a crime" - Balzac

  7. The following user says thank you to wagmare for this useful post:

    killrazor (18th January 2010)

Similar Threads

  1. no compile error, but error on run with QMenu QAction
    By sincnarf in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2011, 11:05
  2. Replies: 0
    Last Post: 4th November 2009, 10:21
  3. Replies: 1
    Last Post: 25th October 2008, 19:18
  4. qTextEdit error - clipboard error
    By bruccutler in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2007, 09:21
  5. ERROR:: QPainter: Internal error; no available GC
    By Krishnacins in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2006, 06:05

Tags for this Thread

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.