How to find signal slot relationship in Qt? - qt

I am recently new to Qt but I have to understand and modify a huge Qt project by someone else.
Is it possible to check the signal slot connection relationship from the source code without finding all the corresponding connect() function?
I heard that the MOC file stores this information somewhere, but I cannot find them out.

If you are looking only for MOC file then you can find it in debug directory. This Directory will be created at same location where your project is located. You need to compiles your code in Qt creator.

Look into the build directory, for every header file that have a class that inherit QObject, moc will generate a cpp file that has a moc_* prefix.
Ex.: ClassA.h -> moc_ClassA.cpp

Related

How do I split out QML files embedded within a DLL?

I have QML file that has been embedded into a dll. I think it was done something like this
How can I embed a Qt resource into a .dll file?
(The second answer).
Is there anyway to split out the QML file to obtain the source code? I am not very familiar with QT framework
If it's embedded via *.qrc, then it's NOT compatible with standard windows/linux (.dll/.so) resource formats. qrc is compiled as xxx_qrc.cpp file and embedded by linker as .obj file with static initialization code. I.e. it's just part of the binary. You can access "contents" of qrc via QFile with "qrc:/." URL. But for that, you have to load DLL with resources embedded in current process, because qrc is hooked up in static initialization (aka DllMain in Windows). Something like:
QLibrary lib("./library.dll");
if (!lib.load())
throw exception(lib.errorString().toStdString());
QFile resource(":/resource.qml");
if (!resource.open(QIODevice::ReadOnly))
throw exception(resource.errorString().toStdString());
resource.copy("./exported.qml");
To explore currently loaded virtual qrc file system tree, you can use QDir(":/"). I guess it's pretty easy to figure out the rest from here.
And of course - you have to be aware what sort of DLLs you are loading into your process, as they may contain arbitrary code that will be executed as you call QLibrary::load!

Qt Creator not able to view source code

I have started to develop an app using Qt Creator, and I am dealing with signals and slots. The problem I have is that I have no way to figure out how to view the code generated from my .ui file I am building. I want to edit some signals and slots but I can't do more than the GUI stuff. Is there a way to view all the source code that is generated when I build my .ui file in creator, or do I have to use another part of the Qt suite?
The .ui file is fed to uic to generate .ui.h file. You should be including that file in your code. Place the cursor over the name of the include file within the #include "foo.ui.h" line, and press F2 to see the contents of the file.
There is no other output from a .ui file. "Qt", specifically the Makefile for your project, doesn't generate anything besides a .ui.h file.

Trouble with setting QT style to external QSS file

I found a QSS file online (http://tech-artists.org/forum/showthread.php?2359-Release-Qt-dark-orange-stylesheet) that I would like to use as the style in my app. I have been trying multiple different ways of importing this file into my program, but every time I run my program, it does not successfully open the file.
Currently I have the file saved as myStyle.qss in the same directory as my project. I have also been hearing about inserting the file into a qrc file. Is this necessary in order to open it, or just a convenient way of storing the file?
My code so far is:
QApplication a(argc, argv);
QFile file(":/myStyle.qss");
file.open(QIODevice::ReadOnly);
QString style(file.readAll());
a.setStyleSheet(style);
file.close();
I have seen this block of code in multiple different places, so I am fairly certain that I have the majority of it right and that my main problem is just in my file placement, or that I have the wrong file path written down.
Thanks!
":/myStyle.qss"it is path which uses for Qt resource system. As you said, this file in the same directory, so try to set nornal path, "myStyle.qss", but be carefully because Qt will search this file in the build directory, so you should place file in build directory.
But when your qss file will be done, then save it in the resources. There are many examples how to do this in the web (for example this. In this case you will need your current path ":/myStyle.qss"
Why do you need resource?
Resources are build into exe file so you never lost this files, user can't delete it or rewrite. If user delete your qss file, all your style will fail, so you should protect it.

How to connect signals to slots manually in .ui files?

Since I'm using SCons instead of qmake, I have no project (.pro) file, and for this reason Qt Creator (I use it only to make GUI) refuses to connect signals to slots. I'd like to manually edit .ui file to add appropriate connections. What should I change?
Use uic to compile the ui file as Karlson said. For example:
uic yourinterface.ui -o uicompiled.h
This way you can generate complete class from the ui files and than you can just plug them into your codebase
qmake will convert the .ui file into .pro and then to a make file. But you still need to run uic to compile your .ui files to generate the meta objects to allow the Signal-Slot connection to occur. Also headers for class definitions might be helpful.
Normally when you subclass the ui you will connect the signals using connect functions to custom defined slots within the subclassed class.

Qt Creator - how to see the code of the designer?

I'm using Qt Creator.
I'm using the signals and slots editor, and I want to see the code it generates.
How can I see the code?
Thanks!
Let's say you have in Qt Creator a form file called widget.ui.
Once you've compiled your project, you'll find in your project folder a filed called ui_widget.h.
If you open it, you'll see the code generated by the uic tool.
when you use qt creater, this one is going to create a file with the name of your project, in my case it is called "build-prueba-Desktop_Qt_5_7_0_GCC_64bit-Debug", then in that file you have to look for a file with the "ui_" prefix, into that, you have the code you need

Resources