Button does nothing
-
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?
-
You're absolutly right! I changed it to a textEdit, it compiles nicely :)
-
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.
-
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?
@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. -
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=ParwizForoghHere 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!
-
Please show the content of ui_mybutton.h and also please don't use the auto-connect feature but do the connects by yourself.
-
Please show the content of ui_mybutton.h and also please don't use the auto-connect feature but do the connects by yourself.
@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 -
@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@homnislash
The file requested is theui_mybutton.hone, not themybutton.hyou show. It should be in the build directory you are compiling in, not the source directory. It is the result of runninguicon the.uifile which was saved from Designer. -
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_HWhat do you have in mind?
-
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=ParwizForoghHere 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!
@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 anyQLineEdit) anywhere in theui_...hfile. I would therefore conclude that your statementui->lineEdit->setText("Hi");will not compile. -
You're absolutly right! I changed it to a textEdit, it compiles nicely :)
-
You're absolutly right! I changed it to a textEdit, it compiles nicely :)
@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!