PDA

View Full Version : Close Button



Lycus HackerEmo
28th December 2009, 03:44
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.


#include <QtGui>
#include "holamensaje.h"

holamensaje::holamensaje(QWidget *parent)
: QWidget(parent)
{
holabutton = new QPushButton("Hola");
salirbutton = new QPushButton("Salir");

connect(holabutton, SIGNAL(clicked()),this, SLOT(hola()));
QObject::connect(salirbutton, SIGNAL(clicked()),this, SLOT(quit()));

QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(holabutton);
layout->addWidget(salirbutton);

QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(holabutton, 0, 0);
mainLayout->addWidget(salirbutton, 0, 1);

setLayout(layout);
setWindowTitle("Hola Mensaje");
resize(250, 100);
}

void holamensaje::hola()
{
QMessageBox msgBox;
msgBox.setText("Hola Mundo!!!");
msgBox.exec();
}


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

spirit
28th December 2009, 06:27
QWidget has not such slot as quit you should use close instead or QCoreApplication::quit.

1.


...
connect(salirbutton, SIGNAL(clicked()),this, SLOT(close()));
...


2.


#include <QApplication>
...
connect(salirbutton, SIGNAL(clicked()),qApp, SLOT(quit()));
...

Lycus HackerEmo
28th December 2009, 21:51
thanks you very much for the help :D

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

Lykurg
28th December 2009, 22:18
everything else in de code is correctly, may be simplified?
No, mainLayout is senseless since you don't use it.

Lycus HackerEmo
30th December 2009, 05:27
thanks for the help, and remove what was not necessary. :D