I wonder what's wrong in my program. Already, grateful!
-
@#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
int main(int argc,char *argv[]) {
QApplication prog (argc,argv);
QWidget janela;
QHBoxLayout *caixa = new QHBoxLayout(&janela);
QPushButton *botao = new QPushButton("Sair");
QLabel *rotulo = new QLabel(argv[1]);
caixa->addWidget(botao,0,0);
caixa->addWidget(rotulo,0,1);
QObject::connect(&botao, SIGNAL(clicked()),
&prog, SLOT(quit()));
return prog.exec();
};@ -
Your code changes should be as follows:-
@#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include <QtGui/QLabel>
int main(int argc,char *argv[]) {
QApplication prog (argc,argv);
QWidget janela;
QHBoxLayout *caixa = new QHBoxLayout(&janela);
QPushButton *botao = new QPushButton("Sair");
QLabel *rotulo = new QLabel(argv[1]);
caixa->addWidget(botao,0,0);
caixa->addWidget(rotulo,0,Qt::AlignHCenter);QObject::connect(botao,SIGNAL(clicked()),&janela,SLOT(close())); janela.show(); return prog.exec();
@}
-
Thank you Sam. Realy is this the error. It've compiled, but do not run.
- Why don't run the exe?
- Why need of the Qt::AlignHCenter?
Sorry me, I'm not speak english very well and I'm newbie on Qt.
-
Hi douglasllima,
I made small changes to your actual program which are :
- Line no. 12 changed to @caixa->addWidget(rotulo,0,Qt::AlignHCenter);@
Here since you are using HBoxLayout so the last argument is for the alignment, you can get more information "here":http://qt-project.org/doc/qt-4.8/qboxlayout.html#addWidget
- Line 13 & 14. changed to @QObject::connect(botao,SIGNAL(clicked()),&janela,SLOT(close()));@
As you have created a widget using QWidget janela; and you are setting It as the parent widget so u need to provide &janela as the reciever for the signals.
- Last added janela.show().
Which actually shows the widget as by default the widgets are invisible(i.e setVisible(false) ).
You can refer to these "video tutorials":http://www.voidrealms.com/tutorials.aspx?filter=qt for learning.
-
Thank you Sam. Problem Solved :D