Results 1 to 5 of 5

Thread: Close Button

  1. #1
    Join Date
    Dec 2009
    Location
    Mexico
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Question Close Button

    I am creating a small program that contains 2 QPusButon, the button "Hola" serves as clicking on the button it should display the message "Hola Mundo", the other button "Salir" what you should do is that when clicked must close the program, but does not work.

    Qt Code:
    1. #include <QtGui>
    2. #include "holamensaje.h"
    3.  
    4. holamensaje::holamensaje(QWidget *parent)
    5. : QWidget(parent)
    6. {
    7. holabutton = new QPushButton("Hola");
    8. salirbutton = new QPushButton("Salir");
    9.  
    10. connect(holabutton, SIGNAL(clicked()),this, SLOT(hola()));
    11. QObject::connect(salirbutton, SIGNAL(clicked()),this, SLOT(quit()));
    12.  
    13. QHBoxLayout *layout = new QHBoxLayout;
    14. layout->addWidget(holabutton);
    15. layout->addWidget(salirbutton);
    16.  
    17. QGridLayout *mainLayout = new QGridLayout;
    18. mainLayout->addWidget(holabutton, 0, 0);
    19. mainLayout->addWidget(salirbutton, 0, 1);
    20.  
    21. setLayout(layout);
    22. setWindowTitle("Hola Mensaje");
    23. resize(250, 100);
    24. }
    25.  
    26. void holamensaje::hola()
    27. {
    28. QMessageBox msgBox;
    29. msgBox.setText("Hola Mundo!!!");
    30. msgBox.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 

    I'm newbie. sorry my English and to use the google translator

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Close Button

    QWidget has not such slot as quit you should use close instead or QCoreApplication::quit.

    1.
    Qt Code:
    1. ...
    2. connect(salirbutton, SIGNAL(clicked()),this, SLOT(close()));
    3. ...
    To copy to clipboard, switch view to plain text mode 

    2.
    Qt Code:
    1. #include <QApplication>
    2. ...
    3. connect(salirbutton, SIGNAL(clicked()),qApp, SLOT(quit()));
    4. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Dec 2009
    Location
    Mexico
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Close Button

    thanks you very much for the help

    one more question, everything else in de code is correctly, may be simplified?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Close Button

    Quote Originally Posted by Lycus HackerEmo View Post
    everything else in de code is correctly, may be simplified?
    No, mainLayout is senseless since you don't use it.

  5. #5
    Join Date
    Dec 2009
    Location
    Mexico
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Close Button

    thanks for the help, and remove what was not necessary.

Similar Threads

  1. How to hide Close Button "X" on Widget ?
    By merry in forum Qt Programming
    Replies: 8
    Last Post: 25th January 2020, 08:03
  2. Disable Close button (X) of a QDialog
    By BrainB0ne in forum Qt Programming
    Replies: 29
    Last Post: 8th December 2009, 17:01
  3. Replies: 5
    Last Post: 21st April 2008, 07:54
  4. Close Button on Modal Widget?
    By vishal.chauhan in forum Qt Programming
    Replies: 5
    Last Post: 18th February 2008, 11:38
  5. Replies: 3
    Last Post: 16th November 2006, 12:24

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.