How do I import my makefile project into QtCreator? - c++

I have previously written a large C++ server and client project (containing multiple .cpp's and .h's which run with makefile). Now I want to modify the client to use a graphical user interface.
Should I import all of my codes to Qtcreator and compile them all in the software? How can I implement the makefile then?
Next, how can I modify my client so that the interfaction with the server is controlled from the graphical interface?

Create a Qt project (I guess, you need Qt Widgets application). Copy your existing files into project's directory. Import all these files to your project. Then look what you have to do in main() function. In Qt project it will be in the file main.cpp, and a minimal code for main() will be automatically created by Qt Creator. So, move the necessary code from your main() function there. Then bit by bit look which parts of your code will interact with Qt. Makefile will be created by Qt Creator. Files mainwindow.cpp and mainwindow.h relate to your main window's GUI.

QtCreator supports working with makefile projects. Basically it becomes a glorified text editor and directly invokes make for your project directory. Some features, like compiling a particular file might not work. See this SO question for more details. And then one can manually link/include Qt for your application's GUI.
Project configuration that is natively supported by QtCreator are qmake files. It converts directly into makefiles. This will provide the best QtCreator experience. So another option would be to convert your makefiles into qmake .pro/.pri files. This will require some effort.
I digress, but if you are going to go this way, I can also recommend CMake. QtCreator has on okay (and constantly improving) support for CMake. So do some other IDEs (CLion, VS). And you will always have the option to convert your CMake files into makefiles, Ninja files, VS solution, or even XCode project.

Related

Setting up C++ include settings for a large library such as Paraview and QT in Eclipse

I have an application where I am compiling against the libraries Qt (5.11) and Paraview (5.6). I am developing in C++ and I am also coding in Eclipse.
Yes, I am aware that Paraview is more of an application then a library. However, I will be using it as a library to intergrate Paraview in my application in order to visualize some data. I could use QT creator and that would take care of the QT library. However, I am not very familiar with QT creator as an IDE and my entire workflow has been based around eclipse. For this, I would like to utilize components that I am familiar with.
Now, as many of you know, the QT library is large, very large. So is Paraview. I could create a search path for each folder containing the header files I need in the C++ include settings. If I go in this direction, then my library search path will be long, very long. Also, there might be a situation where I need to change computers (for whatever reason), I would then need to edit the search paths for the new computer and that will take time.I had thought that I could only include the paths to the include files that I needed. And I have started to do that. However, when I compile my application, I noticed that the libraries would use include files that are located in a directory that Eclipse is not even searching in. At the end of the day, I would need to include all of the directories to which the header files are stored in.
I was wondering if there might be a better method to reference all of the files that my project needs? Both come with make files (I believe that Qt includes a QMake file?). Is there a simpler method to include all of the files instead of editing the C++ include path for eclipse? I did see an option for QMake in Eclipse, is there anything that I can do with that feature to compile to QT library with my application?
Thank you and any feedback is appreciated. Also, feel free to suggest edits or clarification so that my description is clear.
Note some good practices when working with eclipse and qt or other large library.
Include the directories with a headers
If you use option "Generate Makefile automatically", add group include path with GUI Eclipse:
copy the directories with a headers (via system explorer);
go to project properties/C/C++Build/Settings/Tool Settings/GCC C++
Compiler/Includes.
paste directories (Ctrl+V) into "Include paths" list.
If you are using a qt-eclipse-integration plugin, you can add folders via the Discovered scanner configuration. You can find it if open: project properties/C/C++ Include Paths and Symbols/Add Contributed...
Create new project
if you already have a customized project, you can use it as a template:
make a copy of the customized project and name "mytempate";
delete all files from "mytempate".
When you want to create a new project, copy the template and specify (in the copy dialog) the path where the source codes are located.
Now you have a finished new project with settings and code.
Change computers
Use one of the ways:
1. Export C/C++ project settings for use in another workspace via project properties/C/C++ General/Paths and symbols/Includes/Export Settings...
2. Pack in the archive eclipse and workspace and copy your another computer.

How to debug xcode project in qt?

I want to embed some UI written using Qt and QML via QMacNativeWidget.
And I want to debug QML using Qt Creator, cause I can't debug QML with XCode. Do you know if it's possible?
You can debug Qt/QML in Xcode since it's essentially just a regular C/C++ project. The only thing you need is a proper Xcode project (.xcodeproj).
You could use CMake for project configuration/generation instead of relying on QtCreator's .pro format. With CMake you could switch between IDEs (project generators is the better term) on demand and try things out when it gets OS specific.
If that's not an option (there might be several reasons), you still can generate an Xcode project from an existing .pro solution via qmake in the command line:
qmake -spec macx-xcode project.pro
This can be found in the Qt for macOS section of the docs.

Deploying Qt QML Compiled Executable

So I have a simple app that uses QML for my graphical interface and c++ code for some of the logic. I was looking for a method to compile the QML into c++ code and link it into my binary and found this page over at the Qt home site:
http://doc.qt.io/QtQuickCompiler/
Basically it says use the resource system for all of my QML graphical interface files and add the QML compiler flag to my qmake config line in my .pro file and everything should be good to go.
As far as I know everything compiles fine, but when I use the the Qt windeployqt.exe tool to get all of the dependency files and test it on a clean system, I get a small white screen as if my QML files were not loaded properly.
I have one c++ reference to my main QML file using "qrc:/mainqml.qml" and that's it.
Any idea what I am doing wrong?
You're using the open source version of Qt. It didn't come with the Qt Quick compiler until Qt 5.11 where it is included - and after a rework, too. So it performs better than precompiled QML did in Qt 5.10 and before.
I get a small white screen as if my QML files were not loaded properly.
... thus you need to deploy these files with the application, otherwise it won't work.
add the QML compiler flag to my qmake config
That flag was a no-op on an open source Qt build until Qt 5.11.
Qt Quick Compiler only shipped with Qt Commercial License, but you can still compile your QML files into qrc file. Starting a Qt Quick application project from Qt Creator does exactly this.
Deploying QML application with windeployqt require additional flag --qmldir, e.g.
windeployqt --(release or debug) --qmldir %PATH_TO_YOUR_QML_FILES% %YOUR_APPLICATION%.exe
It will parse your qml files and deploy all qml imports you used.

qt creator project change directory

I want to redeploy an existing application developed in C++, using Fltk toolkit, Clam compiler and make files. I want to use now Qt Creator to manage the project.
I created a new project, importing the application files in Qt, with a new Mercurial repository, and I have now the set of files used by my project, which compiles and runs finely.
But the Qt project files are within my src directory and I'd like to put them, with Mercurial repo, outside, in a specific build dir.
How can I relocate the project files and Mercurial repo? I've seen nothing in Qt wizards to do that. What files and paths do I change? How, eventually, can I use Scons instead of make?
SCons has a toolset for QT that you can load when creating the Environment, as follows:
env = Environment(tools = ['qt'])
There is a more advanced qt toolset called qt4, that can be downloaded separately, here.
Once you load this toolset, you can then use the Moc(), Uic(), and related Construction Variables as mention in the SCons man page.
As for how to specify the location of the build files, there are plenty of other Questions/Answers in Stack Overflow that address this.

Using Qt with Visual Studio without add-in

I recently started using Qt library and I've got a question.
Is this possible to use Qt with Visual Studio without special add-in?
I want to just design the UI using qt designer and do the rest in VS Express.
How do I do that?
Thanks.
Yes you can, if you would prefer not to use the QtVSAddin it is very easy to use Qt with VS Express without the VS add-in and without having to do any of the uic or moc steps manually. Let QMake (installed with Qt but not part of the QtVSAddin) create your VS project file and do all your project setup in a qmake project file. Whenever you make a change like adding/removing a form or source, modify the qmake project file and regenerate the VS project. Don't modify the VS project file at all, treat it only as a temporary item. QMake will add the rules automatically to the VS project file to rerun uic and moc, you don't need to do anything if you're just modifying source code or forms.
For configuration management purposes I find this a much cleaner approach to use this workflow as you treat the VS project file as only a temporary item (they tend to diff badly and are a pain to maintain in version control).
A couple snippets to help you out:
In your qmake project file ensure you add the following line into it so that VS project files are generated when running on Windows (qmake defaults to generating a makefile).
your_qmake_proj.pro
win32: TEMPLATE = vcapp
Additionally, it's convenient to have a batch file to rerun qmake so you don't have to bring up a command prompt and set environment up (or change directory to your project in a command prompt that already has the environment setup). If you haven't set the various Qt environment variables with Windows (or prefer not to) make sure to add them to your batch file.
makevcproj.bat
set QTDIR=C:\Qt\x.y.z
set PATH=%PATH%;%QTDIR%\bin
set QMAKESPEC=win32-msvcXXXX
qmake your_qmake_proj.pro
pause
CMake is also an answer and it does work with express versions of Visual Studio. I mean if you use the Qt support in CMake you can develop Qt projects in Visual Studio (like I have done for years) without the Qt Addon. I install the addon just for the debug expansion that comes in the same package.
It is certainly possible, but without the add-in you will need to UI and MOC the needed files either before you compile the rest within VS, or through pre-compile scripting.
Specifically:
uic generates the headers from .ui files.
and
moc generates the additional implementation files for classes that has Qt macros in it.
The add-in helps you call these smoothly on the required files before compiling the rest.
It's is possible if you create the UI in QtCreator and manually setup VS in a way that generate the UI and MOC files.
But it's too much work and you can use QtCreator which is an amazing light IDE.