How to keep track of signals and slots in Qt? - qt

This question is not directly about programming, but I hope that it still fits here: When programming with Qt I have the problem that after some times my subclasses are getting extremely large which leads to a lot of signals and slots in each class I have to connect later. Therefore I was wondering if there is a simple possibility to keep track of all the signals and slots, for example to tell me if I forgot to connect a signal, or to show me all connections of one signal if it is connected more than once. Is there a tool or a function in Qt for that, or should I rather stay with pen & paper for keeping track of them?

Conan is a C++ library that provides run-time introspection of object
hierarchies, object inheritance, signal/slot connections, and signal
emissions.
GammaRay is another advanced analyser which can show signals/slots.

Related

How to go on next page using push button in qt c++ with out use of signal and slots?

I created table widget with check box and push button.
Now ,how to go on next page with all checked data, after click on push button.
the initial question was:
How to go on next page using push button in qt c++ without use of Qt signals and slots?
This is practically impossible, and certainly inadvisable, since Qt signals and slots is the basic foundational mechanism of Qt, used everywhere inside it.
Be sure to take more time to understand Qt signals and slots and study several Qt tutorials and examples. Consider also studying the source code of Qt5 itself (since it is free software). And you can also find many Qt open source applications (e.g. on github, gitlab, inside a Linux distribution, etc...) which should be inspirational (if you don't have time, you could pay some Qt consulting corporation to do your work).
My recommendation is to create some Qt QPushButton (perhaps subclassing that) and connect its clicked signal to your appropriate slot somewhere. The calculator example should be inspirational. You probably should subclass QTableWidget to add a new slot, and use that for your m_pTableWidget or at least declare your MainWindow::on_pushButton_clicked as a public slot (and of course connect it appropriately).
If you don't want to use Qt signals and slots, you should give up using Qt and choose some other widget toolkit. They all have some notification machinery (at least based on callbacks), and IMHO the design of Qt signals and slots is quite good (and sometimes better than what other toolkits provide).
Read also How to debug small programs
It seems that you don't understand the design principles of Qt (i.e. the fact that Qt signals and slots are central to Qt, so you should use them extensively). So I recommend taking a few days to study carefully the documentation of Qt (it is well written, but extensive; start with Getting Started Programming with Qt Widgets) and the source code of existing examples (including Qt itself); throw your current code to the trash bin; then rewrite it with an iterative and incremental development approach : code a few dozen lines at once, compile them (with all warnings and debug info, so g++ -Wall -Wextra -g with GCC), improve them to get no warnings, test your incomplete program - using the GDB debugger -, make sure it works as you want it to, and add one more small feature (perhaps just a single new widget) and repeat. Of course, use a version control system (I recommend git) and commit your code frequently (at least, at every loop of your iterative and incremental development approach).
NB. you have changed your question entirely (at first, you refused to use Qt signals and slots; now you accept to use them). Of course, you need to read carefully the documentation of every used widget (including the superclasses), notably of QTableWidget and of QTableView. And you need to define what a "page" is (and what going to the next page means), since QTableWidget don't know about them.
take time (several days or a few weeks) to read the documentation of Qt.

Dynamic connecting/disconnecting signals and slots

My program has two states and it can switch between them for some reasons. In these states the program needs to receive different signals, which means it has to connect and disconnect certain signals during the run.
How bad is such approach?
It's a fine approach, I've used it before without issues. Depending on what you're actually doing a QSignalMapper might be of use for you.

Qt Signals and Slots overhead for embedded linux

I'm just curious how much overhead I might incur in a program that... abuses signals and slots ridiculously. Our app has almost everything connected via signals and slots. We've replaced calling functions with signals and slots for general data flow so we're passing data along a crazy chain.
I've already shown some concern on the design on this to see how easy it will be to debug/follow later but I'm curious about the performance we'll see. We have a small app now, but I imagine we'll see some issues as the program grows out of control.
Just to give a small idea of how much we are abusing signals, we are emiting a signal to call a logging function

qt thread options

I'm currently writing a programme which has a function to hash a number of files in the background. I've read the Qt4 documentation a number of times over and I still can't really figure out which threading option is best for this.
http://doc.qt.io/qt-5/thread-basics.html
There's really no need to update the GUI when it's done with each file, I just don't wish to block the GUI and I really only need a single signal/slot connection upon completion. I'm thinking of extending QThread for a hashing thread. Does this sound reasonable/right?
I have this article bookmarked as it nicely illustrates the use of QThread and highlights some common misconceptions about it. Sample code available, which runs without blocking the GUI. Sample is hosted on RapidShare, but they seem to have implemented some sort of timed waiting period since I last used it.
This sounds like a good place to use the QtConcurrent::map() function. The map function can apply the same operation to a container of objects, in your case, files. Once you start the map function, you can create a QFutureWatcher and connect to its finished signal to be notified when all of the work is done.

Any UML-like modeling tool for QT signals and slots?

Is it any uml-like modeling tool available that can design (draw) classes and can visually represent QT signals and slots, they connections?
The signal/slog mechanism is essentially a mechanism for registering callbacks. So your question could be paraphrased as: "How do I model callbacks in UML". I'm not sure if there is a good answer since callbacks are not really an object oriented construction. Conceptually the observer pattern would be closest.
You can try Enterprise Architect as it supports UML 2.1 and allow to create user defined diagrams.
These connections are dynamic, so I'm not sure it's even possible to represent them in a static way (as in a diagram).
Also, most often, they are tightly bound in time and code (i.e. you create two objects and then connect them). From the code, it should be pretty obvious what happens and why, making any extra documentation dangerous (since the best it could do was to document the current state and it would always be in danger to be out of date unless it was generated from the source, or rather from data gathered during the runtime of the application).

Resources