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();
    };@



  • so what? What error does it show?



  • maybe you should use the botao variable in connect like this:
    @
    QObject::connect(botao, SIGNAL(clicked()),
    &prog, SLOT(quit()));@



  • 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&#40;&#41;;
    

    @}



  • Thank you Sam. Realy is this the error. It've compiled, but do not run.

    1. Why don't run the exe?
    2. 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 :

    1. 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

    1. 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.

    1. 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



  • You are welcome :) Kindly Edit your first post and prefix [Solved] to the title.

    Happy Coding!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.