Results 1 to 20 of 32

Thread: How to create custom slot in Qt Designer 4.1?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create custom slot in Qt Designer 4.1?

    Quote Originally Posted by cioannou
    I mean that I press my helloButton but no QMessageBox appears.
    You don't instatiate your class anywhere.

    Try:
    Qt Code:
    1. int main( int argc, char **argv )
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. bullshit *window = new bullshit();
    6. window->show();
    7.  
    8. QMessageBox::information( window, "startup msgbox", "The factory default will be used instead." );
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    PS. Please, next time choose a different name for your class.

  2. #2
    Join Date
    Jan 2006
    Location
    Athens-Greece
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create custom slot in Qt Designer 4.1?

    Quote Originally Posted by jacek
    You don't instatiate your class anywhere.

    Try:
    Qt Code:
    1. int main( int argc, char **argv )
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. mydialogclass *window = new mydialogclass();
    6. window->show();
    7.  
    8. QMessageBox::information( window, "startup msgbox", "The factory default will be used instead." );
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    PS. Please, next time choose a different name for your class.

    Ooops. This was really noob.

    Sorry for the class name, it just came out from my dissapointment.

    Already 'renamed' it.
    Last edited by cioannou; 16th January 2006 at 19:18.
    If there weren't noobs there would be no experts

  3. #3
    Join Date
    Jan 2006
    Location
    Athens-Greece
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create custom slot in Qt Designer 4.1?

    I am sorry but it still doesn't work.

    If I connect the button to an existing slot e.g. accept() then the button works.


    Qt Code:
    1. #include <qapplication.h>
    2. #include <qdialog.h>
    3. #include <qmessagebox.h>
    4. #include "ui_MyDialog.h"
    5.  
    6. class MyDialog : public QDialog
    7. {
    8. public:
    9. MyDialog(QWidget *parent = 0);
    10. private:
    11. Ui::MyDialog ui;
    12. private slots:
    13. void msgbox();
    14. };
    15.  
    16. MyDialog::MyDialog( QWidget *parent )
    17. {
    18. ui.setupUi(this);
    19.  
    20. connect(ui.helloButton,SIGNAL(clicked()),this,SLOT(msgbox()));
    21. connect(ui.pressMe,SIGNAL(clicked()),this,SLOT(accept()));
    22. }
    23.  
    24. void MyDialog::msgbox()
    25. {
    26. QMessageBox::information(0, "test","message");
    27. }
    28.  
    29. int main(int argc, char **argv)
    30. {
    31. QApplication app(argc, argv);
    32. MyDialog *window=new MyDialog;
    33.  
    34. window->show();
    35. return app.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 
    If there weren't noobs there would be no experts

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create custom slot in Qt Designer 4.1?

    Quote Originally Posted by cioannou
    I am sorry but it still doesn't work.
    Because there is no Q_OBJECT macro, you need it if you define new signals or slots in your class.

    Qt Code:
    1. class MyDialog : public QDialog
    2. {
    3. Q_OBJECT
    4. public:
    5. ...
    6. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Custom signal in qt designer
    By txandi in forum Qt Tools
    Replies: 1
    Last Post: 4th December 2008, 20:25
  2. create a custom slot, hints?
    By pledians in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2008, 14:26
  3. How to create Custom Slot upon widgets
    By ashukla in forum Qt Programming
    Replies: 6
    Last Post: 8th September 2007, 14:07
  4. Replies: 2
    Last Post: 12th July 2007, 09:55
  5. custom slot + Designer
    By bashamehboob in forum Qt Tools
    Replies: 1
    Last Post: 28th April 2006, 15:17

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.