Auto connection not being assigned/called in 2 of 4 cases
-
Currently I am maintaining a not so small program (about 400000 lines) heavily relying on auto connections. I know that auto connections are not so recommended in the community, but I am lazy, and up to yesterday I never encountered any issue. In this code from my Mainwindow owning among others 4 QToolButton(s) connected to 4 slots like.
void MainWindow::on_firstToolButton_clicked() { mainController->openFirst(); updateNavigation(); } void MainWindow::on_prevToolButton_clicked() { mainController->openPrev(); updateNavigation(); } void MainWindow::on_nextToolButton_clicked() { mainController->openNext(); updateNavigation(); } void MainWindow::on_lastToolButton_clicked() { mainController->openLast(); updateNavigation(); }
Due to compatibility reasons all is written for Qt 5.43.
With the yesterdays compilation the connection to method 2 and 3 were not called anymore while method 1 and 4 are still working Ok. This was verified using the debugger with a breakpoint at the first line of each method. Deleting the complete build folder and rebuilding all did not solve the issue. Then I erased the code for the slots from header and source and I used the QDesigner to newly assign the slots using the "Goto slot..." popup menu item and filled in the code again. Now it is working again. Strangely enough GIT does not report any change of the header and sources between the yesterday and today versions. (Hard to compare the ui files, but the auto connection is not defined in the ui or?).
It looks, as if the moc compiler was confused by something yesterday and therefore the connections were not properly assigned in the code. Did any body experience a similar issue and is anybody there who can explain what could have happened. Is this behaviour connected to the unreliability of auto connections reported sometimes?
May be I have to mention, that the same source code is compiled in 2 different projects, where the above cited MainWindow and its ui are just orphan code (disabled by some compiler variables), but sharing the same controller code for opening and closing files.
-
@pbUser said in Auto connection not being assigned/called in 2 of 4 cases:
Did any body experience a similar issue and is anybody there who can explain what could have happened. Is this behaviour connected to the unreliability of auto connections reported sometimes?
I ran into this multiple times in my early times with Qt, and its exactly the reason why I report it as unreliable and why I'm not using it at all. Sadly I can't tell you what exactly was going on its is code parsing/code generating magic 🤷‍♂️ who knows
-
@All Compared to an auto- connection writing a manual connection requires much more time and is more difficult to debug (exp. finding a particular connection in the source – The Goto slot… helps finding the location in the source). In this relatively large project it would take more than a month to repair all connections. I personally like these kinds of automatisms.
Therefore I did some further analysis. First of all the auto-connections are only non reliable in terms of understanding what is going on. But the reported issue here is 100% reproducible.
In fact the moc is not guilty at all and compiles correctly as the dispatcher code being produced by the moc has all the required calls:void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) { if (_c == QMetaObject::InvokeMetaMethod) { MainWindow *_t = static_cast<MainWindow *>(_o); switch (_id) { ... case 35: _t->on_firstToolButton_clicked(); break; case 36: _t->on_prevToolButton_clicked(); break; case 37: _t->on_nextToolButton_clicked(); break; case 38: _t->on_lastToolButton_clicked(); break; case 39: _t→on_navigationLabel_linkH …
This dispatcher method is called from another method
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { … }
and that one is called from a code section only displayed in assembly code.
Assuming, that the _id for the dispatcher might be wrong I added a breakpoint to check, but while for all other buttons this call is executed, pressing the prev and next button this metacall method not even reached.As it tends to be reproducible I analysed the source files and with the help of GIT I figured out, that the only difference is in the MainWindow.ui:
... 1968 1968 <property name="locale"> 1969 1969 <locale language="English" country="UnitedStates"/> 1970 1970 </property> 1971 <zorder>toolWidget</zorder> 1972 1971 </widget> 1973 1972 <widget class="GraphicsWidget" name="recentPage"> 1974 1973 <property name="locale"> ...
)* The first two columns are showing the line numbers as shown with GIT before/after
Somehow the designer added the <zorder> key somewhen before yesterday, and re-assigning the slots was removing this line again.
I have to add that the toolWidget is a container with a QGridLayout for all my buttons (about a dozen more) used to fade in and out the buttons simultaneously.
For me it looks like that auto-connections can safely be used, unless a <zorder> key is present in the .ui file.
So the remaining questions are:- What did the designer cause to add the <zorder> key?
- Why only 2 QToolbutton were affected, but all others are working Ok?