Various activities to make the code shinier :)
Description
Details
- Differential Revisions
- D3491: Fix compile warning in krArc
Restricted Differential Revision
Related Objects
- Mentioned In
- R167:34159361b0c8: Fix compile warning in krArc
If somebody has too much free time (I don't :) I suggest replacing all connect() lines with the new signal/slot syntax in Qt5. Details: https://wiki.qt.io/New_Signal_Slot_Syntax
The main advantage is that connection errors are detected at compile- and not runtime. Plus lambda support.
And also for new code (if you agree)!
Hello,
I started to work on replacing old connect() wih Qt5 syntax.
Alex wrote me that it would be the best to do automatically by some script, I don't see it realistic.
There are some tricky cases, which I don't know how to convert. May be you can help me.
- Overloaded signals, slots
For this I use QOverload<>::of , so it is fine
- Overloaded signals/slots with default parameters:
Example connect(_tabbar, SIGNAL(newTab(QUrl)), this, SLOT(slotNewTab(QUrl))); {PanelManager.cpp, line 73}
slotNewTab has two overloads, so I have to use QOverloaded, I want to call this one: void slotNewTab(const QUrl &url, bool setCurrent = true, KrPanel *nextTo = 0);
When I put to the list just one parameter, compiler can't match it, when I put there all three, then slot have has more parameters then signal, which is not allowed.
Do you have some trick for this?
I could get rid of the overload functions by renaming one of the functions.
- Parameter are different, but it doesn't matter in Qt4. Example: connect(leDistinctName, SIGNAL(textChanged(QString)), SLOT(setModified())); {ActionProperty.cpp, line 72}
Here I suppose that the QString parameter is thrown out and slot is called with default parameter, which is not QSTring: void setModified(bool m = true);
In Qt5 there is parameter type mismatch.
Can you help me with this?
- Parameter mismatch: connect(this, SIGNAL(readyReadStandardOutput()), SLOT(receivedOutput())); {KrLinecountingProcess.cpp, line 28}
?
Thank you for help,
Miro
Hi Miro,
Me too. It would be good to have it and should be possible with advanced C++ knowledge and huge effort. This is probably the reason why nobody did it yet. If it exists if would be included in Clazy which isn't the case.
- Overloaded signals/slots with default parameters: Example connect(_tabbar, SIGNAL(newTab(QUrl)), this, SLOT(slotNewTab(QUrl))); {PanelManager.cpp, line 73}
It can be solved with lambdas:
connect(_tabbar, &PanelTabBar::newTab, this, [=](const QUrl &url) { slotNewTab(url, true, nullptr); });
Also mentioned in https://wiki.qt.io/New_Signal_Slot_Syntax
- Parameter are different, but it doesn't matter in Qt4. Example: connect(leDistinctName, SIGNAL(textChanged(QString)), SLOT(setModified())); {ActionProperty.cpp, line 72} Here I suppose that the QString parameter is thrown out and slot is called with default parameter, which is not QSTring: void setModified(bool m = true);
Yes, also only solvable with lambda:
connect(leDistinctName, &KLineEdit::textChanged, this, [=]() { setModified(true); });
- Parameter mismatch: connect(this, SIGNAL(readyReadStandardOutput()), SLOT(receivedOutput())); {KrLinecountingProcess.cpp, line 28}
Same as above:
connect(this, &KrLinecountingProcess::readyReadStandardOutput, [=]() { receivedOutput(); });
(you can omit "this" for the slot object - it is the default - and the default argument.)
Cheers
Thank you for help,
lambdas work fine ! :)
What about private signals. I have problem with them here:
connect(job, SIGNAL(processedAmount(KJob*,KJob::Unit,qulonglong)),
this, SLOT(slotProcessedAmount(KJob*,KJob::Unit,qulonglong)));
File: AbstractThreadedJob.cpp line: 131
Signal processedAmount is private, but there is thes if def after Signal definition:
Q_SIGNALS:
#if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) && !defined(IN_IDE_PARSER)
// TODO KF6: Use QPrivateSignal instead, to allow for new signal-slot syntax
private: // don't tell moc, doxygen or kdevelop, but those signals are in fact private
#endif
So it seems that we have to define one of these variables not to have these signals private.
What do you think?
Hello,
I have submitted the first patch here regarding signals and slots. It doesn't solve all the connect() statements. There many hundreds of them. I want to do it in more patches. One reason is that this is my first patch to this project. So I didn't work at something for 6 months and then struggle to submit it. It is here, can you check it? https://phabricator.kde.org/D16223.
Thank you,
Miro
Hello Guys,
I have submitted next patch regarding new style of connect(): https://phabricator.kde.org/D16397
Can you check it please ?
Thank you,
Miro
Hello All,
I have submitted next patch: https://phabricator.kde.org/D16689
Can you check it please ?
I have also updated QTimer::singleShot to the new format.
What is still missing:
- Private slots of KJob class. Example: connect(job, SIGNAL(speed(KJob*,ulong)), this, SLOT(slotSpeed(KJob*,ulong))); This is a part of KF5 library, so it is not possible to change it.
- Signals of Synchronizer private class. Example: connect(synchronizer, SIGNAL(synchronizationFinished()), this, SLOT(synchronizationFinished())); Here it could be declared as public, is it ok?
- QMenu signals highlighted and activated. They seems to be deprecated in Qt5. Is it bug? Can it removed?
Thank you,
Miro