Any one idea how to get reference of QPushButton defined in QT .ui file.
We can create button QPushButton btnOK = new QPushButton("OK", this);
this I know. But how can I link it with button reference in .ui file.
Any suggestion!
Any one idea how to get reference of QPushButton defined in QT .ui file.
We can create button QPushButton btnOK = new QPushButton("OK", this);
this I know. But how can I link it with button reference in .ui file.
Any suggestion!
Say you have a MyWidget.ui file that describes a widget. In this widget, you have a push button named btnOk;
In your code, you typically have the following:
#include "ui_MyWidget.h"
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget() : QWidget() {
m_ui.setupUi(this);
// now this is what you want:
m_ui.btnOk->setText("Hello World!");
}
private:
Ui::MyWidget m_ui;
}
To make this work, you have to be sure to list your MyWidget.ui file in your qmake or cmake based project, so that the ui_MyWidget.h file is automatically created (make sure you have the include paths set correctly).
Further, if you do not want to find the QPushButton based on the variable name, you can also use QObject::findChild(). The string you need then is probably "btnOk", i.e. uic sets this name automatically to the objectName
.