Clicked signal not emitted
-
Hello guys,
I have a problem: i connected the clicked signal to a slot function but it is never emitted even if the PushButton looks as pressed and release graphically.
Using emit button->clicked() the signal is fired, so I think that the connect works well.I paste here some code:
void Ui_MainWindow::setupUi(QMainWindow *MainWindow) { if (MainWindow->objectName().isEmpty()) MainWindow->setObjectName(QString::fromUtf8("MainWindow")); MainWindow->resize(800, 600); actionNew_File = new QAction(MainWindow); actionNew_File->setObjectName(QString::fromUtf8("actionNew_File")); actionOpen_File = new QAction(MainWindow); actionOpen_File->setObjectName(QString::fromUtf8("actionOpen_File")); actionLogout = new QAction(MainWindow); actionLogout->setObjectName(QString::fromUtf8("actionLogout")); actionTintero_0_1 = new QAction(MainWindow); actionTintero_0_1->setObjectName(QString::fromUtf8("actionTintero_0_1")); centralwidget = new QWidget(MainWindow); centralwidget->setObjectName(QString::fromUtf8("centralwidget")); verticalLayoutWidget = new QWidget(centralwidget); verticalLayoutWidget->setObjectName(QString::fromUtf8("verticalLayoutWidget")); verticalLayoutWidget->setGeometry(QRect(10, 30, 191, 501)); verticalLayout = new QVBoxLayout(verticalLayoutWidget); verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); verticalLayout->setContentsMargins(0, 0, 0, 0); avatarLabel = new ClickableLabel(verticalLayoutWidget); avatarLabel->setObjectName(QString::fromUtf8("avatarLabel")); avatarLabel->setAlignment(Qt::AlignCenter); verticalLayout->addWidget(avatarLabel); usernameLabel = new QLabel(verticalLayoutWidget); usernameLabel->setObjectName(QString::fromUtf8("usernameLabel")); usernameLabel->setAlignment(Qt::AlignCenter); verticalLayout->addWidget(usernameLabel); recentDocsLabel = new QListView(verticalLayoutWidget); recentDocsLabel->setObjectName(QString::fromUtf8("recentDocsLabel")); verticalLayout->addWidget(recentDocsLabel); scrollArea = new QScrollArea(centralwidget); scrollArea->setObjectName(QString::fromUtf8("scrollArea")); scrollArea->setGeometry(QRect(210, 30, 581, 501)); scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded); scrollArea->setWidgetResizable(true); scrollAreaWidgetContents = new QWidget(); scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents")); scrollAreaWidgetContents->setGeometry(QRect(0, 0, 579, 499)); docTableWdg = new QGridLayout(scrollAreaWidgetContents); docTableWdg->setObjectName(QString::fromUtf8("docTableWdg")); docTableWdg->setGeometry(QRect(10, 10, 561, 481)); scrollArea->setWidget(scrollAreaWidgetContents); [...] } // setupUi [...] QLabel *newDoc = new QLabel(); auto createDocButton = new QPushButton(); createDocButton->setEnabled(true); createDocButton->setText("new document"); QFrame *container = new QFrame(); container->setLayout(new QVBoxLayout); container->layout()->addWidget(newDoc); container->layout()->addWidget(createDocButton); this->docTableWdg->addWidget(container, 0, 0); bool success = connect(createDocButton, &QAbstractButton::clicked, this, &Ui_MainWindow::createDocument); qDebug()<<success; //this prints true [...] void Ui_MainWindow::createDocument(){ qDebug()<<"i'm here"; }
Thanks in advance for helping
-
@dual
Hi
The name seems a bit odd Ui_MainWindow.
You are not editing the auto-generated file ?class Ui_MainWindow { public: QWidget *centralwidget; ..... void setupUi(QMainWindow *MainWindow) {
This one ?
it has this warning in top
maybe you must expand it.I would assume
void Ui_MainWindow::createDocument(){
qDebug()<<"i'm here";
}should be
void MainWindow::createDocument(){
qDebug()<<"i'm here";
} -
@mrjj yes I'm using the auto-generated file but I deleted from my project the .ui file in order to avoid the problem in the top comment.
I paste here the class declaration:class Ui_MainWindow : public QMainWindow { Q_OBJECT private: [...] QWidget *centralwidget; QWidget *verticalLayoutWidget; QVBoxLayout *verticalLayout; [...]
Btw emitting the "clicked" signal in code, the slot triggers.
-
Hi,
Do not edit the auto-generated file. It even has a warning on top saying so.
You have to edit the other on that makes use of that generated class.
-
@SGaist hi, thanks for the reply.
Can you explain better this concept? I've previously modified the auto-generated file with other stuff, but the only thing that doesn't work is the pushButton, the remaining stuff works well.Sorry for these silly questions, but I am a newbie in qt.
-
The most simple is to take a look at the Qt Designer Calculator Form Example.
-
@SGaist thank you again. So my last question is: how can I modify the gui obtained with the auto-generated file in a "legal" way? Is it possible in code or should I draw the .ui file and auto-generate the .h file again? And again, let's suppose I have to modify an auto-gen .h file in some way after some time, how can I do?
-
What modifications do you have in mind ?
Again, this is a generated file so do not even store in your version control system. It's created based on the .ui file and will be regenerated when that file is modified.