Create First Project in QtCreator, problems with kits - c++

I've just switched to QtCreator for C and C++ developing. I have problem in creating first project, in particular with compiler kits I suppose.
When I go to create a new project, I have the error message that no kits is available.
As you can see, I don't know why it is shown that Qt Version is invalid. How could I solve?

You should first install your C++ compiler. You should also define your compiler in "Compilers" section. If you also want to use Qt you should set the compiler for your kit in the "Kits" section.

When you install QtCreator on MAC OS X you can find it in
/applications/qt
in this folder there is another folder called
5.2.1
Here there are all the compilers.
So to solve the issue you can either add, in QtCreator options, the path of every qmake.bin file or cut the 5.2.1 folder and paste in
/Users/YOURNAME/qt
creating qt folder if it doesn't exist.
PS: I've tried to make the directory invisible, but if I do so, I get errors using the second method

Related

Cannot run Qt Creator GUI outside of Qt. "The application was unable to start correctly (0xc000007b)" error

I downloaded C++ code from GitHub to tag images for training an object detector using Machine Learning.
Within Qt Creator 4.2.1 Based on Qt 5.8.0 (MSVC 2015, 32bit), I was able to compile and run the code. Unfortunately, I was not able to run the .exe outside of Qt Creator.
Initially, I received an error that
"The program can't start because libgcc_s_dw2-1.dll is missing".
Thanks to
QT The program can't start because libgcc_s_dw2-1.dll is missing, that was fixed easily by adding
"QMAKE_LFLAGS += -static"
to the .pro file. Now, when I run it I get
"The application was unable to start correctly (0xc000007b). Click OK to close the application."
I was able to reproduce the error using the simple "Hello World" default project that appears when you create a Qt Widget Application. This led me to believe something was wrong with my installation.
Based on the advice of this article: https://stackoverflow.com/questions/12099117/32-bit-qt-application-on-win-7-x64-wont-run-but-runs-fine-from-qt-creator, I used Dependency Walker to identify possible causes. I expected to see only a few items that I can follow up on. Instead, I received a list of close to 100 missing .dll files. All the files started with
"API-MS-WIN ###.DLL" or "EXT-MS ###.DLL"
where ### represent some additional text characters, for example;
"API-MS-WIN-SHCORE-STREAM-WINRT-L1-1-0.DLL"
I'm attaching a sample output.
Another suggestion was to copy over
libwinpthread-1.dll, libstdc++-6.dll, libgcc_s_dw2-1.dll.
That did not work either.
My next move was to simply get the latest version of QT and wish for the best. I installed Qt Creator 4.8.1 Based on At 5.12.0 (MSVC 2015, 32 bit). This time, I could not even get the code to run in the IDE. I received 1000+ error messages!
Based on advice from several pages, I added
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
to the .pro file and it still would not compile.
Also, I verified that the application is being built as a 32bit application. I'm running on a 64 bit Windows 10 system.
If anyone would like to take a crack at it to see if they can create a working .exe, here is the link: github.com/clavicule/BBTag
Qt provides a tool to copy the necessary dlls to the folder of your executable.
The tools is called windeployqt.exe and comes with your Qt installation. For me it is located at C:\Qt\5.9.1\msvc2015_64\bin\windeployqt.exe. You will have to look at your installation path and probably the msvc_32 folder to find it.
Then you go to the folder with your executable in it, oben a command prompt or powershell and execute path\to\windeployqt.exe yourProgram.exe and it will automatically copy the necessary dll files to this folder. Afterwards you can run your program without issues.
The official documentation for the tool can be found here.
Alternative 1: While developing you could use QtCreator which automatically adds the paths to the dlls when running your program - make sure to include them if you deploy your program!
Alternative 2: Add the path to the necessary dlls to your PATH variable. This isn't recommended either, since everyone who gets your program would have to do the same to run it.
I figured it out! My installation of Anaconda (a Python distribution popular for data science and machine learning) is the culprit.
From: #remy-lebeau
The application was unable to start correctly (0xc000007b)
The error:
"The application was unable to start correctly (0xc000007b) ..."
is a good indicator that the 32-bit app tried to load a 64-bit DLL. At first, this did not make sense since I verified many times that I was using the 32 bit version of Qt.
It turns out that the installation of the 64 bit version of Anaconda also contained many Qt5 dlls used for the PyQt5 package. Since the path to this folder came before the path to my c:\Qt...\bin folder, it was used in the build instead of the actual 32 bit version installed with Qt. This was not obvious because I was unaware of PyQt5 so I had no idea that it came with Anaconda. A simple reordering of the path entries using the System Environment Variables interface AND a system restart fixed the problem.
Silver lining: I now know C++ and designing GUIs w/ QT and PyQt5
Thanks #albertmand and #jwernerny

Adding MinGW compiler to QT 5.6.0 Windows

I am a Total Noob at this and I know nearly nothing about this.
I just started using Qt Creator for windows 5.6.0 and While I wrote my first "Hello World" code..
I was asked to add a kit. I searched the net for similar issues and it said that I needed a compiler for Qt. Thus, I installed MinGW from QtForums
now when go to Tools->Options->Build&Run->compiler, I can not understand how do I add it to the list.
Please help me through it?
To just get started the easiest thing to do would be to go here:
Link to Qt downloads page
Scroll down and select Qt 5.6.0 for Windows 32-bit (MinGW 4.9.2, 1.0 GB) this will download the installer (its about 1 GB). Run it and choose all the default options. Then you will have Qt 5.6 with mingw and Qt Creator all setup ready to go.
Note: Before you start that its probably best to delete your current version - if you are not attached to it in any way :)
If you want to fix your current setup, then it might be longer-winded to find out what you are missing for mingw. For example you need the mingw qmake file that would be located here (using default install options):
C:\Qt\Qt5.5.1\5.5\mingw492_32\bin\qmake.exe
to create your "Qt Version" part of the kit. And the actual mingw compiler, which is located here (using default install options):
C:\Qt\Qt5.5.1\Tools\mingw492_32\bin\g++.exe
to create your compiler. Once you have both of these then you can put them together to create your new kit.
But to just add a compiler all you need to do is:
Click compilers tab
Click add and select mingw
A new compiler is added, click it
You will see some options below, add your compiler executable path in (like the one above for example).
And you are done - there are some other options, but you probably don't need to use them.
note my paths are for qt 5.5.1 (obviously) so slightly different to 5.6 :)
update
Its all been moved around! - here are the new paths:
offline-installers
old-version-archives
Well. I was unable to provide the data before but it all makes more sense now.
What I had installed was Qt for windows 64-bit (vs 2013, 836mb).
Hence, Instead of MinGW, I have msvc2013_64. It does have qmake.exe but doesnt have g++.exe. And I had downloaded it separately.
You're answer was very helpful.
Added MinGW packages to QT installation with the QT Maintenance Tool (C:\Qt\MaintenanceTool.exe)
It allows to add/remove components via the qt repositories. So no need for re-installation.

How to make Qt4 work using Code::Blocks in Linux Mint

I'm trying to use Qt4 using the Code::Blocks IDE. I'm running Linux Mint and I'm getting some errors. I looked around and found some people that had the same problem as me, but I can't seem to get their solutions working on my computer.
I installed Qt4 using the command
sudo apt-get install qt4-dev-tools
And when I type whereis qt4, I get qt4: /usr/lib/qt4 /usr/include/qt4 /usr/share/qt4
If I select "Create new Projet" in Code::Blocks and Select Qt4 project, it asks for Qt's location, which is $(#qt4) by default. If I click next, it says Code::Blocks doesn't know the "qt4" variable and gives me a prompt to set the base location, the include directory, etc.
Since I don't have any idea as to what I should be putting in there since nothing works (either it says "QTCore cannot be found in the specified directory", or the "lib" directory couldn't be found, etc.).
I tried what was posted on this forum: http://crunchbang.org/forums/viewtopic.php?id=18210, but it didn't solve my problem and I get the same errors.
In the "/usr/share/qt4" directory, there's a link to the "include" directory, but not to the "lib" directory.
I'm pretty new to Linux and all of this, so I'd like it if the answer was very detailed explaining what I did wrong / what I have to do.
Install the QtSDK
As a first step I would advise you to download directly the QtSDK, from the project site here.
Note: You could also use the precompiled version for your Mint version,
but in my personal experience, when working with external SDK,
you have more independence in development, it also allows you to work
freely with multiple versions of Qt simultaneously without move any
dependence of your OS.
You can follow the graphics steps to install the SDK, I advise you to check the option "download source", later this is going to be used for debugging code, and if necessary will allow the recompilation of some classes.
Now your QtSDK is installed on the folder eg "/usr/local"
So, all references inside your IDE should refer to this location.
Install the C::B
You can use the version available in "Software Manager"
Configure the C::B
When we start a new project and asks the location of our SDK we indicate this directory /usr/local/QtSDK/Desktop/Qt/4.8.1/gcc
Now the project is ready!
Note: "/usr/local" and "4.8.1" are variables depending on where
and what version you have installed.
Is very likely that your build directory, is not correctly assigned in "Settings->Compiler and Debugger->Toolchain ...->Compiler's Directory"
will be the default "usr" which should be replaced by "/usr/bin"
Now, when compiling with the standard project ".pro" and if your project has the requirement to use a "moc" tool strategy, the simplest way to do that, is use a customized Makefile, with all stages of compilation.
To learn how to make a customized makefile, you can read this answer.
And although I would advise again:
Although that CB is an optimal environment for working with wxWidgets, and C/C++ in general, I personally think that in the case of working with Qt, QtCreator provides a development environment more native and optimized to work with your projects QT.

Qt Creator build error with under Windows

I want to port a multiple project MSVS solution to Qt Creator.
I created the .pro files for the projects and added them to Qt Creator.
When I build the projects I always get the same error shown below.
By the way I am using Qt 4.6.3 (VS 2008). What may cause this?
It's difficult to say what the problem is frmo the jom.exe output.
It might be that the command it's trying to execute on the console is too long (MS reference).
A similar problem was reported here, although is not clear if it was solved.
I suggest you upgrade to a more recent version of Qt and try again (sorry).
You could change your make step from jom to nmake (found in the projects window) to see if it gives you a more detailed error.
It also seems that you do not have any source code files in your project, just your library's header files.

Developing QT applications in Xcode?

My IDE of choice for the Mac (at least for C++ and Objective-C development) is Xcode. I have a 64-bit Intel Mac with OS X Lion installed, and Xcode version 4.2 downloaded from the Mac App Store.
My problem is that Qt is apparently not compatible with Xcode 4 (it crashes when launching projects generated by qmake), so I'm basically asking how I can integrate Qt with Xcode. I don't have to be able to run and debug the project from Xcode, just build it.
So I thought it might be a solution to use qmake as an external build system within Xcode, the problem is that I have no idea how to set up qmake as my build system, so that I can develop my Qt applications in Xcode 4.
Please help me! :)
Google shows up many pages, but this Qt4 with Xcode page appeared at first glance to be a fairly definitive resource. However, it was last changed in 2006.
Please check out: http://qt-project.org/doc/qt-5/macosx.html
There is a much more recent Qt Developer Network forum post that seems to have good info in it. Specifically, this reply from August 19, 2011 gives a complete recipe.
Update 25/05/2016:
The first two links are now dead, and not archived due to robots.txt.
However, I've updated the link to the forum post.
And here's a copy of emiguel's answer. It is now 5 years old, so I don't know how current it still is.
Hi,
To solve my problem I did the following.
First I`m going to have a subproject in Qt that mantains the graphical interface, I created this project as a C++ library, so I could include this in the main project.
The main project is a C++ project in Xcode (which is a plugin template with a lot of configurations).
Second, I ported the Qt project to Xcode using the spec macx-xcode parameter.
Third, having both projects in Xcode, I can attatch the library (in Qt) to the main project. To do this, right click in the xcode project and click in the "existing file..." option, select the xcodeproj file from the Qt project. Finally add the library to the linkage phase, this is done by dragging the lib file, wich is under the xcodeproj file, to the "Targets" section in the "Link binary with Libraries".
Fourth, import the Qt framewoks to the main project, to do that, right click in the main project, click in add a existing framework, select the Qt features used by the project (ex. QtSDK/lib/QtCore.framework)
And finally, add the header and library paths in the main project. Click in project menu->project settings, set the header search paths option with the Qt headers (ex QtSDK/include//) and the library search paths (ex QtSDK/lib//**).
That's all, now I can instantiate my own Qt widgets from the C++ project.
Note: I have to do an additional step because my target was i386 and the downloaded Qt version were 64 bit, so I downloaded the sources and compiled it for i386.
Now I have another problems about drawing inner the plugin... but I think that will be for another post.
Thanks a lot for your help
Finally, current information on building Qt in Xcode is available in Qt for OS X - which is too long to copy here, and will be maintained and updated by Qt...