How do I find my way around the code?

I’ve been tasked with adding something to the UI of QGC. I started by running it in Callgrind and twiddling a button, but the time spent responding to the button was so tiny I couldn’t find it. Then I ran gdb on it and stopped it and tried to single-step into an event handler, but not having the source code of whatever I stopped it in, I couldn’t. Then I grepped the files in ~/src/qgroundcontrol/src/ for QButton, QMenu, QLabel, and QComboBox. The only one of those I found is QComboBox, which is subclassed to QGCComboBox, which isn’t used anywhere. Where can I start understanding the UI code?

Ui src is mostly done on the .qml files. QButton etc are an extension to qml Button, mainly for auto change colors to the chosen dark or light color theme.
FlightView.qml and FlightMap.qml are good starting points to study the code.
Further read qt qml language and qt signaling techniques.

Thanks! I’m not familiar with qml; in my code I put the classes defining UI in header files, such as tincanvas.h, with the implementation in source files, such as tincanvas.cpp. Signals are connected by methods of the classes. I don’t see any .cpp (or .cc) files in qgroundcontrol/src/ui/toolbar/; where’s a method I can set a breakpoint on?

Here is how I go about it:
I find a distinct phrase around the control I want to edit, ctrl+shift+f it and generally find it on qml, after that I continue to ctrl+shift+f my way back to a Q_property or Q_invokable, fallowing binded signals and variables. after that you could put a break point in there.
I am not very experienced with qt, so this might not be optimal

ctrl-shift-f makes Kate go full-screen. What editor are you using, and what does ctrl-shift-f do?

Hey phma, I just found myself in your exact same situation, and I’m completely lost. Have you found an efficient way to navigate this mess? I tried using the GammaRay inspector tool, but it doesn’t seem to work well with QGC.
Thanks in advance!

So far I’ve found that classes with Q_PROPERTY (which I never heard of before looking at this code) appear to correspond with UI elements defined in QML. I set a breakpoint in BlankPlanCreator::createPlan and trigger it by clicking on the corresponding button.

@phma & @cyands, The entire User Interface of QGroundControl is done in QML. QML is a declarative language and is completely different from Qt Widget based application. qmlbook is an excellent resource for understand how to program using Qt/QML language. I recommend you read this book, then you will have a better understanding of QGC source code.

The starting point of QGC application is src/ui/MainRootWindow.qml. QGC software uses very consistent coding style. Naming conventions they use are very good which really helps in understanding the code.

Few excellent debugging features in QGC are Mock Link and Console under Application Setting. Through Mock Link you can simulate a connection to different types of Vehicle without actually connecting to the simulator. This helps in speeding up the debugging process.

Through Console -> Set Logging option you can enable console logging based on each individual module. Instead of setting a breakpoint and debugging through GDB, I find it very easier to put debug messages in the code and enable Console logging.

1 Like

Thank you for the very useful tips!

so the user interface is qml, and the rest of the code is c++?

yes. " " (fill up 20 chars)