Hello!
I'm having a problem with connect() function and I wasn't able to find a solution exactly despite numerous related problems have being reported in this forum.
the problem is: always when I want to make a connect() between a not-ui declared QPushButton and a slot function in a given thing ether the compiler returns error saying "no matching function for call ..." or else its says, when I run the software, that it couldn't find the slot.
So here is my situation: I'm creating a software that has a MenuBar with one of the options being "Settings". In the settings (a QWidget) there will be a couple of boxes and RadioButton and so forth to choose a couple of options to change my software. In order to make things simpler, I decided to create a specific class for almost all the windows (QWidgets, normally) that will be openend by clicking in the MenuBar.
The logic is supposed to be as follow:
1. in the MainWindow (that is connected with the ui and so its the place where the MenuBar click will be called) a pointer to the class with the Setings parameters is created. If the button in MenuBar "Settings" is pressed, a function opens a correspondent method in the windows class.
2. There, one of the automatic methods that are called is one that creates and connects all the buttons in the Settings window:
Code:
void MenuWindows::createSettingsBut() { //Cria botões de clique connect(v_butOK, SIGNAL (released()), this, SLOT (update())); connect(v_butCAN, SIGNAL( released() ), v_setboxwidget, SLOT( close() ) ); //Cria ComboBox (que dá para escolher várias opções) - Qt19 v_combobut1->addItem("Green"); v_combobut1->addItem("GBR"); //Cria botões de escolha (radio) - Qt18 ... }
one of this buttons is "v_butOK", which is a QPushButton with "OK" on it.
3. So the guy using the software will set the configurations in the other buttons as he pleases, and once he wants to get out with the new configuration, he press "OK".
4. In this case, the "OK" QPushButton must be connected with a slot method of the class (class name is "MenuWindows" as seen above) which is named "update()". This method will verify each of the settings parameters to see which changes were made and, based in the analysis, will change the configurations of the software and close the Settings window:
Note: this method is not finished (this is why there is just qDebugs() in it).Code:
void MenuWindows::update() { if (v_checkbut1->isChecked()) { qDebug() << "Graph 1 on."; } else { qDebug() << "Graph 1 off."; } if (v_checkbut2->isChecked()) { qDebug() << "Graph 2 on."; } else { qDebug() << "Graph 2 off."; } v_setboxwidget->close(); }
In the case, this update() method was declared as "public slots:" in the header file of the class "MenuWindows".
But when I run the software as it is above, the compilation says "Object::connect: No such slot QObject::update() in menuwindows.cpp:28". And the slot is there!
What am I missing?
Thanks!