Results 1 to 5 of 5

Thread: slot issue

  1. #1
    Join Date
    Nov 2007
    Posts
    24
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default slot issue

    Hi guys,

    Could you tell me why the "about" messagebox doesn't trigger whe I'm doing this :


    Qt Code:
    1. class Main: public QMainWindow
    2. {
    3. //Q_OBJECT
    4.  
    5. public:
    6. Main();
    7.  
    8. public slots:
    9. void about();
    10.  
    11. private:
    12. QToolBar *m_tb;
    13. QMenu *m_settings;
    14. void createMenubar();
    15. };
    16.  
    17.  
    18. void Main::about()
    19. {
    20. QMessageBox::about( this, tr("About"), tr("test") );
    21. }
    22.  
    23.  
    24.  
    25. void Main::createMenubar()
    26. {
    27. QMenu *menu;
    28. QAction *atTop;
    29.  
    30. atTop = new QAction("Always on top", this);
    31. connect(atTop, SIGNAL(triggered()), this, SLOT(about()));
    32.  
    33. menu = menuBar()->addMenu(tr("&Settings"));
    34. menu->addAction(atTop);
    35. }
    36.  
    37.  
    38.  
    39. Main::Main(): QMainWindow()
    40. {
    41. createMenubar();
    42. }
    43.  
    44.  
    45.  
    46. int main(int argc, char *argv[])
    47. {
    48. QApplication a(argc, argv);
    49.  
    50. Main *w = new Main();
    51. w->show();
    52. return a.exec();
    53. }
    To copy to clipboard, switch view to plain text mode 


    I cannot find my fault

    Thanks for your help
    Last edited by wysota; 17th September 2010 at 18:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: slot issue

    Q_OBJECT macro is commented out.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2007
    Posts
    24
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: slot issue

    Yes, thanks, I did that to avoid the message :
    undefined reference to `vtable for Main'

    I guess it's a probem with MOC...
    Last edited by stef13013; 17th September 2010 at 21:28.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: slot issue

    I guess you write all that code in one file?
    If so write this at the end (after your code):
    Qt Code:
    1. //...
    2. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Then run Clean All from the Build menu in Qt Creator, and it should run and build (without undefined vtable)

    But it's better if you learn the C++ way of writing classes: a .h for declaration and a .cpp file for the implementation (and in that way you don't need to include the file that moc generate for you)

  5. #5
    Join Date
    Nov 2007
    Posts
    24
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: slot issue

    Indeed, it was just a "quick and dirty little test"

    By the way, you're right Zlatomir, thanks for your answer and advice...

Similar Threads

  1. QFileDialog Signal / Class Slot issue
    By Wasabi in forum Newbie
    Replies: 5
    Last Post: 7th August 2010, 23:48
  2. QSlider slot trigger issue
    By depsch in forum Newbie
    Replies: 1
    Last Post: 18th September 2009, 05:25
  3. qt signal/slot auto-connect issue
    By parnedo in forum Qt Programming
    Replies: 9
    Last Post: 16th July 2009, 12:55
  4. Signal and Slot Issue
    By dlrlsqa1 in forum Newbie
    Replies: 5
    Last Post: 23rd March 2009, 12:44
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.