Page 3 of 3 FirstFirst 123
Results 41 to 47 of 47

Thread: Q_OBJECT macro problem

  1. #41
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Q_OBJECT macro problem

    but its in public slots

  2. #42
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Q_OBJECT macro problem

    It's in the public slots of class Calculator and NOT of class QLCDNumber. So change your connect statement to this:
    Qt Code:
    1. QObject::connect(equal, SIGNAL(clicked()), this, SLOT(calculate()));
    To copy to clipboard, switch view to plain text mode 
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  3. The following user says thank you to Archimedes for this useful post:

    bijan311 (26th March 2010)

  4. #43
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Q_OBJECT macro problem

    thanks so much

  5. #44
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Q_OBJECT macro problem

    wait... now I changed the code up a bit and I think need to update the .moc file but can't find out how
    he is main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "calc.h"
    3.  
    4. int main(int argc, char **argv){
    5. QApplication app(argc, argv);
    6. Calculator w;
    7. w.show();
    8. return app.exec();
    9. }
    10. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    and calc.h
    Qt Code:
    1. #ifndef CALC_H
    2. #define CALC_H
    3.  
    4. #include <QPushButton>
    5. #include <QLabel>
    6. #include <QSpinBox>
    7. #include <QLCDNumber>
    8. #include <QHBoxLayout>
    9. #include <QVBoxLayout>
    10.  
    11. class Calculator : public QWidget {
    12. Q_OBJECT
    13. public:
    14. Calculator(QWidget *parent = 0) : QWidget(parent){
    15. minus = new QPushButton("&-");
    16. add = new QPushButton("&+");
    17. multiply = new QPushButton("&X");
    18. divide = new QPushButton("&/");
    19. num1 = new QSpinBox;
    20. num2 = new QSpinBox;
    21. answer = new QLCDNumber(3);
    22.  
    23. QHBoxLayout *layout = new QHBoxLayout;
    24. layout->addWidget(num1);
    25. layout->addWidget(num2);
    26. layout->addWidget(answer);
    27.  
    28. QHBoxLayout *button1 = new QHBoxLayout;
    29. button1->addStretch();
    30. button1->addWidget(add);
    31. button1->addWidget(minus);
    32. button1->addStretch();
    33.  
    34. QHBoxLayout *button2 = new QHBoxLayout;
    35. button2->addStretch();
    36. button2->addWidget(multiply);
    37. button2->addWidget(divide);
    38. button2->addStretch();
    39.  
    40.  
    41. QVBoxLayout *mainLayout = new QVBoxLayout(this);
    42. mainLayout->addLayout(layout);
    43. mainLayout->addLayout(button1);
    44. mainLayout->addLayout(button2);
    45.  
    46. connect(minus, SIGNAL(clicked()), this, SLOT(subtract()));
    47.  
    48. }
    49. public slots:
    50. void subtract(){
    51. answer->display(num1->value()-num2->value());
    52. disconnect();
    53. }
    54. void plus(){
    55. answer->display(num1->value()+num2->value());
    56. }
    57. void times(){
    58. answer->display(num1->value()*num2->value());
    59. }
    60. void divider(){
    61. answer->display(num1->value()/num2->value());
    62. }
    63. private:
    64. QPushButton *minus;
    65. QPushButton *multiply;
    66. QPushButton *divide;
    67. QPushButton *help;
    68. QSpinBox *num1;
    69. QSpinBox *num2;
    70. QLCDNumber *answer;
    71. };
    72. #endif CALC_H
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Q_OBJECT macro problem

    You don't need the #include anymore as your class is in a header file now. Just run qmake.

  7. #46
    Join Date
    Feb 2010
    Posts
    42
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Q_OBJECT macro problem

    but if i take out
    Qt Code:
    1. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    I get this error
    Qt Code:
    1. C:\MinGW\include\c++\3.4.5\bits\stl_algobase.h:(.text$_ZN10CalculatorD1Ev[Calculator::~Calculator()]+0xb)||undefined reference to `vtable for Calculator'|
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Q_OBJECT macro problem

    Yes, which is why you need to run qmake, to update the project file to resolve that error.

Similar Threads

  1. Problems with the Q_OBJECT-Macro
    By tokstolle in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2009, 18:09
  2. Problems with Q_OBJECT macro
    By dbrmik in forum Qt Programming
    Replies: 21
    Last Post: 26th February 2009, 15:10
  3. Q_OBJECT macro and link errors
    By pscheven in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2008, 14:23
  4. Q_OBJECT macro - what exactly does it do?
    By magland in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 11:30
  5. Q_OBJECT macro issue
    By kandalf in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2007, 20:28

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.