Why
-
Hello. I am writing code for a QT Widget application.
I made buttons in the past and used slots to enable actions for them when the user uses them. However, I changed the name of one of the buttons from
action_import
tomenuBar_import
after doing the plug. Because of this, I now have two cases, where one applies to the previous name of a widget that does not exist.How can I fix this? I receive an error upon trying to run my code since
case 0
is bad now. Now, I can removecase 0
to get my code to work, but I do not want to do this each time.Error:
void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) { if (_c == QMetaObject::InvokeMetaMethod) { auto *_t = static_cast<MainWindow *>(_o); (void)_t; switch (_id) { case 0: _t->on_actionImport_triggered(); break; case 1: _t->on_menuBar_import_triggered(); break; case 2: _t->on_menuBar_export_triggered(); break; case 3: _t->on_button_quizInfo_clicked(); break; default: ; } } (void)_a; }
Thank you!
-
Edit: Pardon the poor title. I forgot to finish it. I will repost with a better title.
-
Hi and welcome to devnet,
Just edit the title, no need to repost.
It seems you are using the auto connect feature.
It would be simpler to manually do the connections yourself. This will also save you time when renaming widgets.
-
Thank you for helping me out.
Would it be alright for you to point me in the direction of disabling auto-connect? I removed the function from the
mainwindow.cpp
altogether, but it still shows up.Furthermore, I added a new button slot by right clicking a new button, then clicking "Go to slot", then adding an action upon click. After removing the resulting code from the
mainwindow.cpp
, I still receive an error for it. -
To stop using auto connection, do not use on_XXX_signalName.
Create slots with meaningful name in the code and then connect them at the end of your constructor.