Results 1 to 2 of 2

Thread: create a custom slot, hints?

  1. #1
    Join Date
    Oct 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question create a custom slot, hints?

    Hi. I've read as much info as i could about creating custom slots, but i still cant get it work, maybe you could give me i hint about what im i doing wrong? The idea is, that when i priss button b, my custom slot 'print' shoud execute, but nothing happens! (no compilation errors or warnings either)

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3. #include <QWidget>
    4. #include <qmessagebox.h>
    5.  
    6. class MyWidget : public QWidget
    7. {
    8. public:
    9. MyWidget(QWidget *parent = 0);
    10.  
    11. public slots:
    12. void print();
    13. };
    14.  
    15. void MyWidget:: print()
    16. {
    17. QMessageBox::information(this, "Some window label here", "hello");
    18. }
    19.  
    20. MyWidget::MyWidget(QWidget *parent)
    21. : QWidget(parent)
    22. {
    23. setFixedSize(200, 120);
    24.  
    25. QPushButton *b = new QPushButton(tr("QT"), this);[/B]
    26. quit->setGeometry(62, 40, 75, 30);
    27.  
    28. connect(b, SIGNAL(clicked()), this, SLOT(print()));[/B]
    29. }
    30.  
    31. int main(int argc, char *argv[])
    32. {
    33. QApplication app(argc, argv);
    34. MyWidget widget;
    35. widget.show();
    36. return app.exec();
    37. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 2nd October 2008 at 17:19. Reason: missing [code] tags

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: create a custom slot, hints?

    * add Q_OBJECT to your class
    * add your header file to your .pro file's HEADERS section
    (or include "#include "yourfile.moc" in yourfile.cpp if your class decl is in your .cpp file)

    PS: at the moment you should get a runtime warning that this slot does not exist

    HTH

Similar Threads

  1. How to create Custom Slot upon widgets
    By ashukla in forum Qt Programming
    Replies: 6
    Last Post: 8th September 2007, 14:07
  2. Replies: 2
    Last Post: 12th July 2007, 09:55
  3. create custom widgets
    By nimmyj in forum General Discussion
    Replies: 1
    Last Post: 20th November 2006, 08:24
  4. custom slot + Designer
    By bashamehboob in forum Qt Tools
    Replies: 1
    Last Post: 28th April 2006, 15:17
  5. How to create custom slot in Qt Designer 4.1?
    By jamadagni in forum Qt Tools
    Replies: 31
    Last Post: 18th January 2006, 20:46

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.