Qt into ObjectiveC code - c++

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.

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.

Linking .ui files into 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.

Using the Qt library in an existing c++ VS2010 program

I'm trying to get the the Qt library to work in an my existing VS2010 project. But I am pretty much stuck.
I have succesuflly compiled the library with nmake on 64 bit and added the Qt adon for vs2010.
But i don't no how to use it in my project, the project makes already use of the boost and the opencv librarys and these work just fine.
I found a thread here on stackoverflow that says I need to edit the vs project file with an text editor but when I do this I cant find the global section that I need to edit.
Can anyone help me with this problem? Thank in advance.
I solved it, wel sort of. I made a new QT project and added my excisting code in the new QT project. I also linked the opencv an boost libs and the application works now!
Thanks for all the comments

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.