Linking .ui files into C++ - c++

I have done all sorts of research into how to build a GUI in C++. I finally downloaded Qt4Designer because I thought that was my best bet. The problem is that I don't know how to use .ui files in my C++ code. I looked at Linking a qtDesigner .ui file to python/pyqt? and Difficult linking ui tree widget and header/cpp files, but I'm not extremely advanced and I don't have a lot of time, so if someone could explain to me exactly how to include the files in my code, that would be great. I admit that can't understand every little detail in that code because I am just starting out in the great world of computer programming. Another part of the problem is that I don't know how to implement the GUI into my code. What that means: If x button is pressed, what does my C++ code do? Please be patient with the question and its naiveness, I'm not an expert and I'm not claiming to be.

Well, you can use QtCreator or you can learn the magic of qmake, which comes with Qt by default. Also you can try CMake QT tutorial which shows you how to build your QT appls but with a more power tool and feature.

Related

Import Qt into an existing Xcode project

I am on MacOS 10.13.3, using Xcode 9 as my IDE, and trying to include Qt 5.10 in my Xcode project. I have installed Qt (with docs and examples) with Homebrew and ran many of them in QtCreator. Everything worked well up to this point.
My Xcode project is an extensive, complex project, the development of which has been active for a few years now, so switching to QtCreator or changing the structure of my project is not an option. I really need to add Qt to my existing Xcode project, which IMHO should be quite a natural thing to do given that Qt is a software development framework. However I have not been able to accomplish that yet. The upside is that in the process I have been learning quite a bit about Qt and its ecosystem. I now know how to use qmake, how to set up and successfully compile a project in QtCreator and how to create an Xcode project from QtCreator using qmake. As I said, I have been running many Qt examples and read pretty much every piece of documentation, blog and SO post I could find about this subject. To my surprise I haven't found a direct solution to this problem anywhere on the net.
So far I have included in my Xcode environment QtCore.framework, QtWidgets.framework and QtGui.framework, configured Xcode with the right search paths (Qt finds its files and frameworks) and include the right Qt headers in the code. However upon building my target I get a series of meaningless compilation errors.
Basically - if my understanding is correct - I can't just import Qt's components and frameworks I need, and set the right paths in Xcode just like I would do with any other framework. Qt 'features' a preprocessing step using MOC and UIC that sets it apart from other tools. So I examined the output of qmake and there are two files that the building system produces - qt_makeqmake.mak and qt_preprocess.mak which I think are responsible for the code generation step. Basically this is what I don't know how to translate into my Xcode environment.
Please feel free to tell me if my approach is not correct.
I am open to any advice or suggestion.
I would really like to integrate Qt into my project as Qt is such a powerful and complete framework. I hope someone will be able to help.
Thank you.
1 / In addition to setting the right path to Qt libraries and header files, which is fromwhat you said already done, you need to invoke the moc (Meta-Object Compiler) on your own Qt class which includes the Q_OBJECT macro. (basically every class you have made that are using signal/slot system).
MOChttp://doc.qt.io/qt-5/moc.html
This step must be done BEFORE compiling the project, and the result (the cpp generated moc files) must be compiled AND linked.
Now I am not an expert in XCode and MacOS development but for sure you have a way to add a custom step in your build process for doing that
2/ For UIC files : follow approximatively what is explained here (answer of Preetam, not the one validated) to obtain a .cpp and an .h file that you must include in your project too.
Hope this answer will help and point you toward the rigth direction.
Here is a post explained more in detail what I explained :
https://fmilicchio.bitbucket.io/2013/01/xcode-and-qt4-and-qt5/?

Adding C++ files to compile and run using Qt creator

I'm really new to Qt creator and actually I think my very short experience with it didn't go so well.
Anyways, my question is:
I used to write C++ programs using Code::Blocks IDE, now I'm trying to make some simple GUI to my program. So that's really why I used Qt creator in the first place.
I have multiple C++ files (.cpp) and (.h) how can I use them into Qt and integrate both "Qt user interface" with my C++ files.
I tried to google about it but got nothing. If anyone can help me how to start, or point out some good tutorial.
You mostly need to write a Qt project file (with some .pro extension) for Qmake (perhaps using qmake -project), then use qmake to generate a Makefile, then use GNU make to build your program.
Qtcreator is an IDE which might help you, but if you want to use some other editor or IDE, you can run the commands mentioned above appropriately. Actually, once you have generated once your Makefile, it might be auto-regenerated appropriately when needed. So configuring your IDE to use make is probably enough.

Qt into ObjectiveC code

As i'am coding in objective-c, i'am wondering if i can put some Qt code in my objective-c project and compile it all together ? i did a research but the answers were kind of shady. If this is possible, do you have a hint or an answer on how to do this please ? Thank you.
It is possible, as I do this the other way round - Use Objective C in a Qt project with Qt Creator. That's easy to do by adding .m or .mm files to the project and linking to the required frameworks.
To add Qt to XCode requires creating a project file from Qt. This post seems to describe steps required to do this.

Qt MOC generated code documentation

I am designing a user interface in Qt, and for longevity reasons I'd like to not require the Qt Meta-Object Compiler be used in future builds. I know the MOC parses certain macros in standard C++ code and generates C++ code based on these.
What I'd like to know is: where is the documentation of this generated code? I'd like to write the generated code directly into my relevant classes. While this might be cumbersome to do now, it will make the UI more stable in the long term by avoiding any issues if Qt disappears and the MOC ceases to exist.
Thanks!
Edit 1:
I am designing a Qt based UI in Visual Studio (NOT Qt Creator), for a C++ application that is not based on the Qt framework. I want to be able to distribute code that can be built as pure C++ with Qt code linked from specific libraries that will be packaged in. I want to be able to build this code on systems that do not have Qt installed. Hence the desire to avoid MOC. I'm not trying to offend any Qt fans out there, Qt is great. However, I need something a little different on this project, so suggestions to "Just use MOC" are not at all helpful.
Edit 2: I'm man enough to admit when I'm wrong. After some more thought and research it's clearly not worth trying what I was planning on doing. I'll just have to save the MOC generated code and distribute it as well. Thanks everyone.
Putting moc output verbatim into your code makes your code less portable, not more, as the moc output format changes more often (currently version 67) than source-incompatible major versions of Qt (currently version 5).
It seems to be on the whole not worth it to try to circumvent the MOC, as everyone here has pointed out to me. My solution will be saving the MOC generated source files in source control and packaging them along with the main application code for distribution.

Use Eclipse/CMake with existing C++ project

I have been using Qt Creator as an IDE for some C++ project (non-QT) and I love it. Recently I have been thinking to try out Eclipse mainly for learning a new tool and also the fact that I'm not a big fan of the debugger mode in Qt Creator!
Anyhow, I figured I could potentially use the makefile generated by the qmake, but though hey let's also learn CMake! So, I was wondering if someone could point me to some nice tutorials on this (I have not had much luck myself)? Specifically, I like to have the ability to create and maintain CMakeList.txt files and build/run the project directly within Eclipse ... just as you would by editing a .pro file inside Qt Creator.
Thanks
CMake includes an Eclipse CDT4 generator since version 2.6; you should probably take a look at this page, it explains three different possibilities for using Eclipse and CMake together. From my personal experience, solution 1 works pretty well in Unix environments.