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. [SOLVED] QPushButton. I click on the button, but nothing not happend.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QPushButton. I click on the button, but nothing not happend.

Scheduled Pinned Locked Moved General and Desktop
24 Posts 7 Posters 32.5k 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.
  • I Offline
    I Offline
    I-sty
    wrote on last edited by
    #1

    Here my, cpp file:

    @void setRefreshSpeed::on_okButton_clicked()
    {
    QApplication::beep();
    MainWindow::freq = ui->spinBox->value();
    ui->setupUi(this);
    setRefreshSpeed::close();
    }@

    The .h file:

    @class setRefreshSpeed : public QDialog
    {
    Q_OBJECT

    public:
    explicit setRefreshSpeed(QWidget *parent = 0);
    ~setRefreshSpeed();

    private slots:
    void on_okButton_clicked();

    private:
    Ui::setRefreshSpeed *ui;
    };@

    So, I click on the button, on the ui form, but nothing not happend. I tired with _clicked(), with _pressed(), but nothing.

    Sorry, for my bad English. My first language is Hungarian.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      The signature of clicked is wrong. You need bool as an argument "(see here)":http://qt-project.org/doc/qt-4.8/qabstractbutton.html#clicked .
      However, pressed should work. Check out the spelling of your push button. Is it spelled "okButton"? Check out the case of the letters. Did you change the name?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • I Offline
        I Offline
        I-sty
        wrote on last edited by
        #3

        I deleted the old "okButton".
        I created a new button.

        @<widget class="QPushButton" name="pushButton">
        <property name="geometry">
        <rect>
        <x>140</x>
        <y>50</y>
        <width>75</width>
        <height>23</height>
        </rect>
        </property>
        <property name="text">
        <string>Apply</string>
        </property>
        </widget>@

        And in the "Slot dialog" I selected "clicked(bool)" event.

        @void setRefreshSpeed::on_pushButton_clicked(bool checked)
        { ... }@

        But nothing.
        I doing something wrong. :(

        Sorry, for my bad English. My first language is Hungarian.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Don't rely on these automatic use-a-specific-name-to-connect features. It is a nightmare to no end, and IMHO it should never have been introduced.

          Simply create a slot that has a name that actually describes what happens, not on what condition it is triggered. Then, explicitly connect the buttons clicked() signal with that slot.

          It will make your life easier as you go along.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            leon.anavi
            wrote on last edited by
            #5

            [quote author="Andre" date="1342512606"]Simply create a slot that has a name that actually describes what happens, not on what condition it is triggered. Then, explicitly connect the buttons clicked() signal with that slot.[/quote]

            I-sty, our wiki has "a simple example about QPushButton and its signals":http://qt-project.org/wiki/How_to_Use_QPushButton.

            http://anavi.org/

            1 Reply Last reply
            0
            • I Offline
              I Offline
              I-sty
              wrote on last edited by
              #6

              [quote author="leon.anavi" date="1342515413"]

              I-sty, our wiki has "a simple example about QPushButton and its signals":http://qt-project.org/wiki/How_to_Use_QPushButton.
              [/quote]

              Thanks Leon, but the button isn't display.

              setrefreshspeed.cpp

              @#include <QPushButton>

              #include "setrefreshspeed.h"
              #include "ui_setrefreshspeed.h"
              #include "mainwindow.h"

              //
              // Global variables
              //

              setRefreshSpeed::setRefreshSpeed(QWidget *parent) :
              QDialog(parent),
              ui(new Ui::setRefreshSpeed)
              {
              ui->setupUi(this);

              QPushButton *button = new QPushButton(this);
              button->setText("Apply");
              button->setGeometry(QRect(QPoint(150, 50), QSize(75, 23)));
              connect(button, SIGNAL(clicked()), this, SLOT(apply()));
              

              }

              setRefreshSpeed::~setRefreshSpeed()
              {
              delete ui;
              }

              void setRefreshSpeed::apply()
              {
              QApplication::beep();
              //MainWindow::freq = ui->spinBox->value();
              //ui->setupUi(this);
              //setRefreshSpeed::close();
              }
              @

              mainwindow.cpp

              @void MainWindow::on_actionOther_triggered()
              {
              Ui::setRefreshSpeed something;
              QDialog *d = new QDialog;
              something.setupUi(d);
              d->show();
              }
              @

              Sorry, for my bad English. My first language is Hungarian.

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

                You need to add the button to the layout and then for the mainwindow/dialog u need to set the layout by calling setLayout(m_layout);

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  I-sty
                  wrote on last edited by
                  #8

                  @#include "setrefreshspeed.h"
                  #include "ui_setrefreshspeed.h"
                  #include "mainwindow.h"

                  #include <QPushButton>
                  #include <QtCore/QCoreApplication>
                  #include <QVBoxLayout>

                  setRefreshSpeed::setRefreshSpeed(QWidget *parent) :
                  QDialog(parent),
                  ui(new Ui::setRefreshSpeed)
                  {
                  ui->setupUi(this);

                  QVBoxLayout * vlayout = new QVBoxLayout(this);
                  
                  button = new QPushButton("Apply", this);
                  button->setGeometry(QRect(QPoint(150, 50), QSize(75, 23)));
                  connect(button, SIGNAL(released()), this, SLOT(apply()));
                  
                  vlayout->addWidget(button);
                  this->setLayout(vlayout);
                  

                  }

                  setRefreshSpeed::~setRefreshSpeed()
                  {
                  delete ui;
                  }

                  void setRefreshSpeed::apply()
                  {
                  QApplication::beep();
                  }
                  @

                  I created one vlayout, I added button to it, but nothing.

                  Sorry, for my bad English. My first language is Hungarian.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    leon.anavi
                    wrote on last edited by
                    #9

                    The example at the wiki works fine. Using layout is recommended but not mandatory. I guess that your button is not displayed because your UI and the following line:

                    [quote author="I-sty" date="1342522046"]

                    @
                    ui->setupUi(this);
                    @

                    [/quote]

                    http://anavi.org/

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goblincoding
                      wrote on last edited by
                      #10

                      You can "use Qt designer":http://doc.trolltech.com/main-snapshot/designer-connection-mode.html to set up the signal\slot connection.

                      Alternatively, why not try this (if you want to do it manually in your constructor):

                      @connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(apply()));@

                      (I assumed your UI button is still called pushButton?)

                      http://www.goblincoding.com

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        I-sty
                        wrote on last edited by
                        #11

                        [quote author="goblincoding" date="1342523306"]You can "use Qt designer":http://doc.trolltech.com/main-snapshot/designer-connection-mode.html to set up the signal\slot connection.

                        Alternatively, why not try this (if you want to do it manually in your constructor):

                        @connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(apply()));@

                        (I assumed your UI button is still called pushButton?)[/quote]

                        I set a other slot, called "slot1", with Qt designer.
                        I debuged, and i gave 3 errors.

                        "Debugging starts
                        Object::connect: No such slot QDialog::slot1() in ./ui_setrefreshspeed.h:57
                        Object::connect: (sender name: 'pushButton')
                        Object::connect: (receiver name: 'setRefreshSpeed')
                        Debugging has finished
                        "

                        This is the line number 57:
                        @QObject::connect(pushButton, SIGNAL(clicked()), setRefreshSpeed, SLOT(slot1()));
                        @

                        Sorry, for my bad English. My first language is Hungarian.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          Did you actually create a slot with that name?

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            I-sty
                            wrote on last edited by
                            #13

                            [quote author="Andre" date="1342525437"]Did you actually create a slot with that name?[/quote]

                            Yes.

                            Sorry, for my bad English. My first language is Hungarian.

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #14

                              Show us the complete code then, please.

                              1 Reply Last reply
                              0
                              • I Offline
                                I Offline
                                I-sty
                                wrote on last edited by
                                #15

                                Can I upload here the files? Or I can only copying?

                                Sorry, for my bad English. My first language is Hungarian.

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  andre
                                  wrote on last edited by
                                  #16

                                  No, you cannot upload files here. You could use pastebin for code sections, or perhaps a public dropbox folder.

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

                                    [quote author="I-sty" date="1342525774"]Can I upload here the files? Or I can only copying?[/quote]

                                    Your wish . You can zip the project folder upload it somewhere and paste the link here or write all the files.

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      Mr.Programmer
                                      wrote on last edited by
                                      #18

                                      You can do this kind of codes automatically with only using Qt Creator.

                                      It binds events and... with using some dialog windows and wizards!

                                      1 Reply Last reply
                                      0
                                      • I Offline
                                        I Offline
                                        I-sty
                                        wrote on last edited by
                                        #19

                                        "on the Google Drive":https://docs.google.com/folder/d/0B2_XIe25TBZFYUdDU0FIRVZxMTA/edit

                                        Sorry, for my bad English. My first language is Hungarian.

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          goblincoding
                                          wrote on last edited by
                                          #20

                                          Your problem is this:

                                          @
                                          void MainWindow::on_actionOther_triggered()
                                          {
                                          Ui::setRefreshSpeed something;
                                          QDialog *d = new QDialog;
                                          something.setupUi(d);
                                          d->show();
                                          }
                                          @

                                          You're creating QDialog object, not a refreshSpeed object and QDialog does not have a slot1() (as your compiler rightfully pointed out). You also do not need to explicitly create or setup the UI (that's kind of the whole point with Qt Designer Form classes :) ). This is what you want:

                                          @
                                          void MainWindow::on_actionOther_triggered()
                                          {
                                          //Ui::setRefreshSpeed something;
                                          setRefreshSpeed *d = new setRefreshSpeed;
                                          d->setAttribute( Qt::WA_DeleteOnClose );
                                          //something.setupUi(d);
                                          d->show();
                                          }
                                          @

                                          http://www.goblincoding.com

                                          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