Qt Slot Return Value
- When the user closes the dialog, exec will provide a useful return value. Typically, to get the dialog to close and return the appropriate value, we connect a default button, e.g. OK, to the accept slot and a Cancel button to the reject slot. Alternatively you can call the done slot with Accepted or Rejected.
- If the signal returns a value, it is a pointer to an object of the return type of the signal, else, it is 0. If the slot returns a value, we need to copy it in arg. If it returns void, we do nothing. The problem is that it is not syntaxically correct to use the return value of a function that returns void.
- The first element of the array is the return value. In our example it is 0 because the return value is void. The 3rd parameter passed to activate is the signal index (0 in that case).
- Status:Reported
- Resolution: Unresolved
- Fix Version/s: None
- Labels:
The following program reproduces the issue:
When I run that program , I get the following output to stdout:
After the sections are resized from 105 (which I assume is their default value) to 210 and 196, signal sectionResized is emitted twice, once for section 0 and once for section 1. You can see that in the first call of the slot connected to that signal, sectionSize(0) and sectionPosition(1) return wrong values. In the second call of the slot, sectionSize(1) returns the wrong value. This behavior occurs not only during the initialization, but also when sections are resized at a later time (as long as sectionResizeMode is ResizeToContents), as attached file example.cpp demonstrates.
Qt Slot Return Value Calculator
Further properties of signal/slots. Qt provides the QObject::sender function, which returns a pointer to the object that sent the signal Note: if the slot was not activated by a signal, the return is undefined. Signals and slots are loosely coupled: A class which emits a signal neither knows nor cares which slots receive the signal. I sometimes use slots that return values in my code. It's nothing special. As for non-void slots in Qt - I'm almost sure there are some. But they are called using QMetaObject::invokeMethod because their value is interesting to the caller so it needs to be retrieved.
I would expect that when sectionResized is emitted, at least sectionSize(logicalIndex) would return the new value. The fact that it doesn't is surprising and can lead to hard to find bugs.
The issue seems to be in QHeaderViewPrivate::resizeSections. In that method, there is a loop that takes care of updating SectionItem objects and emitting signal sectionResized. It emits the signal for section with visual index i in its ith iteration, but it updates the corresponding SectionItem object in a later iteration, after it has reached a section with a different new length (if there is no such section, the SectionItem object is updated after the loop is finished). Therefore, the SectionItem object still contains outdated values when signal sectionResized is emitted for the corresponding section.
Qt Slot Return Value Estimator
Attachments
Gerrit Reviews
- Assignee:
- Qt Quick and Widgets Team
- Reporter:
- Jernej Krempuš
- Votes:
- 0Vote for this issue
- Watchers:
- 1Start watching this issue