Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I wonder what's wrong in my program. Already, grateful!

I wonder what's wrong in my program. Already, grateful!

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    douglasllima
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #2

      so what? What error does it show?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deimos
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          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;;
          

          @}

          1 Reply Last reply
          0
          • D Offline
            D Offline
            douglasllima
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sam
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                douglasllima
                wrote on last edited by
                #7

                Thank you Sam. Problem Solved :D

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #8

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

                  Happy Coding!!!

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved