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. Button does nothing
Qt 6.11 is out! See what's new in the release blog

Button does nothing

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 904 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.
  • H Offline
    H Offline
    homnislash
    wrote on last edited by
    #1

    Hi all, okay, now I have a push button on the app but it can do nothing :(
    I tried several methods, but nothing seem to activate it:

    • I tried this tuto: https://www.youtube.com/watch?v=VigUMAfE2q4&ab_channel=ProgrammingKnowledge
    • and this one: https://www.youtube.com/watch?v=dOovH6TvaY4&ab_channel=VoidRealms

    Any help please? To make something that works a bit?

    JonBJ 1 Reply Last reply
    0
    • H Offline
      H Offline
      homnislash
      wrote on last edited by
      #10

      You're absolutly right! I changed it to a textEdit, it compiles nicely :)

      JonBJ 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Please show your code.

        That said, beside YouTube, the Qt documentation is full of examples to get you started. You might want to dig in it a bit.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • H homnislash

          Hi all, okay, now I have a push button on the app but it can do nothing :(
          I tried several methods, but nothing seem to activate it:

          • I tried this tuto: https://www.youtube.com/watch?v=VigUMAfE2q4&ab_channel=ProgrammingKnowledge
          • and this one: https://www.youtube.com/watch?v=dOovH6TvaY4&ab_channel=VoidRealms

          Any help please? To make something that works a bit?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #3

          @homnislash
          Not many people here are going to want to watch videos. The idea is you show a bit of code --- code you can paste --- you are trying. And you explain what is wrong or what is not working.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            homnislash
            wrote on last edited by homnislash
            #4

            Thank you so much for your help, I could display some text through the button clic via this tuto :
            https://www.youtube.com/watch?v=Pb-XC5Q5zLU&ab_channel=ParwizForogh

            Here is a snippet of my code to illustrate: the cpp file:

            #include "mybutton.h"
            #include "./ui_mybutton.h"
            
            MyButton::MyButton(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MyButton)
            {
                ui->setupUi(this);
            }
            
            MyButton::~MyButton()
            {
                delete ui;
            }
            
            
            void MyButton::on_pushButton_clicked()
            {
                ui->lineEdit->setText("Hi");
            }
            
            

            I had a hard time trying to have an interaction to find a solution to display some text. See you soon!

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Please show the content of ui_mybutton.h and also please don't use the auto-connect feature but do the connects by yourself.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              H 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                Please show the content of ui_mybutton.h and also please don't use the auto-connect feature but do the connects by yourself.

                H Offline
                H Offline
                homnislash
                wrote on last edited by
                #6

                @Christian-Ehrlicher Thanks for the reply, I am not sure to understand, I have a .h file, is this what you want to see?

                #ifndef MYBUTTON_H
                #define MYBUTTON_H
                
                #include <QMainWindow>
                
                QT_BEGIN_NAMESPACE
                namespace Ui { class MyButton; }
                QT_END_NAMESPACE
                
                class MyButton : public QMainWindow
                {
                    Q_OBJECT
                
                public:
                    MyButton(QWidget *parent = nullptr);
                    ~MyButton();
                
                private slots:
                    void on_pushButton_clicked();
                
                private:
                    Ui::MyButton *ui;
                };
                #endif // MYBUTTON_H
                
                JonBJ 1 Reply Last reply
                0
                • H homnislash

                  @Christian-Ehrlicher Thanks for the reply, I am not sure to understand, I have a .h file, is this what you want to see?

                  #ifndef MYBUTTON_H
                  #define MYBUTTON_H
                  
                  #include <QMainWindow>
                  
                  QT_BEGIN_NAMESPACE
                  namespace Ui { class MyButton; }
                  QT_END_NAMESPACE
                  
                  class MyButton : public QMainWindow
                  {
                      Q_OBJECT
                  
                  public:
                      MyButton(QWidget *parent = nullptr);
                      ~MyButton();
                  
                  private slots:
                      void on_pushButton_clicked();
                  
                  private:
                      Ui::MyButton *ui;
                  };
                  #endif // MYBUTTON_H
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #7

                  @homnislash
                  The file requested is the ui_mybutton.h one, not the mybutton.h you show. It should be in the build directory you are compiling in, not the source directory. It is the result of running uic on the .ui file which was saved from Designer.

                  1 Reply Last reply
                  1
                  • H Offline
                    H Offline
                    homnislash
                    wrote on last edited by
                    #8

                    thanks for clarifying, here you go:

                    /********************************************************************************
                    ** Form generated from reading UI file 'mybutton.ui'
                    **
                    ** Created by: Qt User Interface Compiler version 6.4.0
                    **
                    ** WARNING! All changes made in this file will be lost when recompiling UI file!
                    ********************************************************************************/
                    
                    #ifndef UI_MYBUTTON_H
                    #define UI_MYBUTTON_H
                    
                    #include <QtCore/QVariant>
                    #include <QtWidgets/QApplication>
                    #include <QtWidgets/QHBoxLayout>
                    #include <QtWidgets/QMainWindow>
                    #include <QtWidgets/QMenuBar>
                    #include <QtWidgets/QPushButton>
                    #include <QtWidgets/QStatusBar>
                    #include <QtWidgets/QTextEdit>
                    #include <QtWidgets/QWidget>
                    
                    QT_BEGIN_NAMESPACE
                    
                    class Ui_MyButton
                    {
                    public:
                        QWidget *centralwidget;
                        QWidget *widget;
                        QHBoxLayout *horizontalLayout;
                        QTextEdit *textEdit;
                        QPushButton *pushButton;
                        QMenuBar *menubar;
                        QStatusBar *statusbar;
                    
                        void setupUi(QMainWindow *MyButton)
                        {
                            if (MyButton->objectName().isEmpty())
                                MyButton->setObjectName("MyButton");
                            MyButton->resize(800, 600);
                            centralwidget = new QWidget(MyButton);
                            centralwidget->setObjectName("centralwidget");
                            widget = new QWidget(centralwidget);
                            widget->setObjectName("widget");
                            widget->setGeometry(QRect(50, 5, 222, 211));
                            horizontalLayout = new QHBoxLayout(widget);
                            horizontalLayout->setObjectName("horizontalLayout");
                            horizontalLayout->setContentsMargins(0, 0, 0, 0);
                            textEdit = new QTextEdit(widget);
                            textEdit->setObjectName("textEdit");
                    
                            horizontalLayout->addWidget(textEdit);
                    
                            pushButton = new QPushButton(widget);
                            pushButton->setObjectName("pushButton");
                    
                            horizontalLayout->addWidget(pushButton);
                    
                            MyButton->setCentralWidget(centralwidget);
                            menubar = new QMenuBar(MyButton);
                            menubar->setObjectName("menubar");
                            menubar->setGeometry(QRect(0, 0, 800, 22));
                            MyButton->setMenuBar(menubar);
                            statusbar = new QStatusBar(MyButton);
                            statusbar->setObjectName("statusbar");
                            MyButton->setStatusBar(statusbar);
                    
                            retranslateUi(MyButton);
                    
                            QMetaObject::connectSlotsByName(MyButton);
                        } // setupUi
                    
                        void retranslateUi(QMainWindow *MyButton)
                        {
                            MyButton->setWindowTitle(QCoreApplication::translate("MyButton", "MyButton", nullptr));
                            pushButton->setText(QCoreApplication::translate("MyButton", "PushButton", nullptr));
                        } // retranslateUi
                    
                    };
                    
                    namespace Ui {
                        class MyButton: public Ui_MyButton {};
                    } // namespace Ui
                    
                    QT_END_NAMESPACE
                    
                    #endif // UI_MYBUTTON_H
                    
                    

                    What do you have in mind?

                    1 Reply Last reply
                    0
                    • H homnislash

                      Thank you so much for your help, I could display some text through the button clic via this tuto :
                      https://www.youtube.com/watch?v=Pb-XC5Q5zLU&ab_channel=ParwizForogh

                      Here is a snippet of my code to illustrate: the cpp file:

                      #include "mybutton.h"
                      #include "./ui_mybutton.h"
                      
                      MyButton::MyButton(QWidget *parent)
                          : QMainWindow(parent)
                          , ui(new Ui::MyButton)
                      {
                          ui->setupUi(this);
                      }
                      
                      MyButton::~MyButton()
                      {
                          delete ui;
                      }
                      
                      
                      void MyButton::on_pushButton_clicked()
                      {
                          ui->lineEdit->setText("Hi");
                      }
                      
                      

                      I had a hard time trying to have an interaction to find a solution to display some text. See you soon!

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #9

                      @homnislash said in Button does nothing:

                      void MyButton::on_pushButton_clicked()
                      {
                          ui->lineEdit->setText("Hi");
                      }
                      

                      I see a slot which I believe will be called correctly.

                      But I see no widget named lineEdit (or for that matter any QLineEdit) anywhere in the ui_...h file. I would therefore conclude that your statement ui->lineEdit->setText("Hi"); will not compile.

                      1 Reply Last reply
                      2
                      • H Offline
                        H Offline
                        homnislash
                        wrote on last edited by
                        #10

                        You're absolutly right! I changed it to a textEdit, it compiles nicely :)

                        JonBJ 1 Reply Last reply
                        0
                        • H homnislash

                          You're absolutly right! I changed it to a textEdit, it compiles nicely :)

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #11

                          @homnislash
                          You seem like an intelligent person. What I do not understand is that you would/should have got a compiler error. Did you not think it was relevant to say "it does not compile on this line" rather than "button does nothing"? I don't mean to sound rude, just this was terribly relevant!

                          1 Reply Last reply
                          1

                          • Login

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