Qt creator needs a compiler - qt-creator

I have problem with Qt compiler.The error is:
Qt Creator needs a compiler set up to build. Configure a compiler in the kit options.
the code is:
#include "mainwindow.h"
#include <QApplication>
#include<QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// MainWindow w;
// w.show();
QLabel *lb=new QLabel();
lb->settext("first label");
lb->setvisible(true);
return a.exec();
}
The version of Qt is 5.3.0 and I have visual studio 2010.
In internet I read the version of Qt must be compatible with visual studio.
I want to know is problem from the version of the Qt and visual studio or another thing?

Qt Creator needs a compiler set up to build. Configure a compiler in
the kit options.
From the menu of QtCreator, Open "Tools>Options>Build&Run>Kits". If no auto-detected configuration, you need configure it manually.
In addition, make sure Qt5.3.0 is compiled with VS2010. If not, download the correct version, or compile Qt source code yourself.

Related

CLion and Qt Framework

So I figured out how to get Qt Framework working with CLion, but I don't have Qt Designer in CLion. How can I make a GUI in CLion using Qt Framework? Every tutorial i've seen uses Qt Creator so I cannot get an answer.
I worked with QtCreator and then with Qt5 libraries on Clion.
For a better understanding see my project at https://github.com/FraScandiffio/Timer_Laboratorio
Search for MyTimerApp.ui .h .cpp files.
1)You need a .ui file: it was created for me by QtCreator: when i worked on Clion i just copied the file into my project folder and add in the SOURCES_FILES.
You can download it from my project: it's the MyTimerApp.ui file but you have to change just 3 words to adapt it to your needs.
Re-name the file with the name that you prefer. Now open the file with a text editor and replace all the "MyTimerApp" with the name that you have just chosen.
2)Add this in your Cmake.txt (the explanation of why you have to do it is here)
cmake_minimum_required(VERSION 3.3)
project({your_project_name})
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(SOURCE_FILES main.cpp MyApp.ui #...)
#... the rest of your cmake.txt ...
Download also MyTimerApp.cpp and MyTimerApp.h files. (i suggest you to create a new .h file and paste into them the code instead of refactor my file)
Open it and replace "MyTimerApp" whit the same name you have chosen before.
obviously add them into the SOURCE_FILES list.
In the main.cpp type
#include "nameyouhavechoosen.h"
#include "QApplication"
#include "QWidget"
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QWidget* MyWidget= new {nameyouhavechoosen};
MyWidget->setGeometry(500,200,617,416);
app.setActiveWindow(MyWidget);
MyWidget->show();
return app.exec();
}
If you run it you should see a very simple window.
In my github repository you can find how to create buttons/timer and more. Anyway Qt documentation is great for learning.

use OpenCV with Clion IDE on Windows

I'm actually looking for a way to create apps with OpenCV with Clion from JetBrains.
I've installed OpenCV with Choco, so I have all the stuff in C:\opencv
this is my projet with Clion
CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories("C:\\opencv\\build\\include\\")
FIND_PACKAGE( OpenCV REQUIRED core highgui imgproc)
set(OpenCV_FOUND TRUE)
set(SOURCE_FILES main.cpp)
add_executable(prog ${SOURCE_FILES})
and the main.cpp:
#include <opencv2/opencv.hpp>
int main() {
cv::Mat img = cv::imread("./test.jpg", -1);
cv::imshow("Mon image", img);
cv::waitKey(0);
return 0;
}
and the response to build is :
undefined reference to `cv::imread(cv::String const&, int)'
and undefined errors for all OpenCV functions
Do you know why it doesn't works?
First of all, you need CMake.
Then you need a compiler of your choise (MinGW, Visual Studio, ...).
Download the OpenCV source files. Link
Unpack to C:\opencv (or a folder of your choice)
Open CMake and select source (directory of 2.) and build for example C:\opencv\mingw-build or C:\opencv\vs-x64-build. Choose one accoring your configuration.
Click Configure and select the generator according to you compiler. MinGW Makefiles in case of MingGW or Visual Studio ... if you are using Visual Studio and so on ...
(If you experience problems with MinGW, ensure that the minGW/bin directory is added to the evironment path labelled, 'PATH')
Wait for the configuration to be done, edit your properties of your needs (in my case I don't need tests, docs and python).
Click Configure again. When everything is white click Generate else edit the red fields.
Open cmd and dir to build directory of 3.
If you chose Visual Studio open the generated solution.
Compile the library. Run mingw32-make (or mingw64-make) or build the BUILD_ALL project from the generated solution in Visual Studio if your choosen compiler is MSVC.
This takes a while.
Once it is done, run mingw32-make install (or mingw64-make install). If you've choosen Visual Studio you need to build the INSTALL project.
This creates an install folder, where everything you need for building your own OpenCV apps is included.
To system PATH add C:\opencv\mingw-build\install\x86\mingw\bin
Restart your PC.
Set up CLion:
You need to download FindOpenCV.cmake and add it to project-root/cmake/.
CMakeLists.txt:
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Where to find CMake modules and OpenCV
set(OpenCV_DIR "C:\\opencv\\mingw-build\\install")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test_cv main.cpp)
# add libs you need
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
# linking
target_link_libraries(test_cv ${OpenCV_LIBS})
main.cpp:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main(int argc, char** argv)
{
if(argc != 2)
{
std::cout << "Usage: display_image ImageToLoadAndDisplay" << std::endl;
return -1;
}
cv::Mat frame;
frame = cv::imread(argv[1], IMREAD_COLOR); // Read the file
if(!frame) // Check for invalid input
{
std::cout << "Could not open or find the frame" << std::endl;
return -1;
}
cv::namedWindow("Window", WINDOW_AUTOSIZE); // Create a window for display.
cv::imshow("Window", frame); // Show our image inside it.
cv::waitKey(0); // Wait for a keystroke in the window
return 0;
}
Build and run main.cpp.
All Paths depend on the setup you make in 2. and 3. You can change them if you like.
UPDATE 1: I updated the post for using a compiler of you choice.
SUGGESTION: Using a package manager like Conan makes life much easier.
I just want to add one more thing in the answer of daB0bby. Few Min-GW Compilers do not support C++ Version 11 or later. This version is required for thread in OpenCV. So I will suggest using TDM-GCC Compiler instead of MinGW Compiler. Install this compiler and set path C:\TDM-GCC-64\bin to the system's environmental variable.

Setting up Qt Creator 3.3.2 and openCV 2.4.11 on Windows

I have a configuration problem while compiling and building a program with Qt Creator and the imageprocessing library openCV on my Windows machine. OpenCV worked some time ago with Visual Studio, but now I want to build programs with Qt Creator. I am working with opencv-2.4.11 and Qt Creator 3.3.2
I started a new program and tried to compile the following code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>
using namespace std;
using namespace cv;
int main()
{
cout << "Hello World!" << endl;
Mat Bild;
return 0;
}
This building process ends with the errors:
C:...\build-Test01-Desktop_Qt_5_4_1_MinGW_32bit-Debug\debug\main.o:-1: In function ZN2cv3MatD1Ev':
C:\opencv\build\include\opencv2\core\mat.hpp:278: Fehler: undefined reference tocv::fastFree(void*)'
C:...\build-Test01-Desktop_Qt_5_4_1_MinGW_32bit-Debug\debug\main.o:-1: In function ZN2cv3Mat7releaseEv':
C:\opencv\build\include\opencv2\core\mat.hpp:367: Fehler: undefined reference tocv::Mat::deallocate()'
collect2.exe:-1: Fehler: error: ld returned 1 exit status
My .pro file includes the “INCLUDEPATH” and the “LIBS”:
INCLUDEPATH += C:\opencv\build\include\ \
C:\opencv\sources\include\
LIBS += -L C:\opencv\build\x86\vc12\lib\
-lopencv_core2411\
-lopencv_calib3d2411\
-lopencv_highgui2411\
-lopencv_imgproc2411\
SOURCES += main.cpp
What am I doing wrong – why do I always get an error :( ?
I tried also different other ways to define the include folders and libs, but I was not able to compile the testcode.
Regards
matl
You are using MinGW compiler and OpenCV extraction doesn't contain libraries built by it. So, you'll have to manually build them using MinGW provided by Qt. Use the following post for help:
How to link opencv in QtCreator and use Qt library
Make sure you have all the environment variables for Qt, MinGW and OpenCV libraries set properly. With all these done you should be all set.
Hope this helps.

Qt5 on windows can't find QSqlDatabase

I try to use sqlite on some qt app but getting error on compile step
Cannot open include file: 'QSqlDatabase': No such file or directory
I use Windows7, qt5.1 compiled with MSVC 2010. I have qsqlite.dll(and other .dlls) in ..Qt_path/plugins/sqldrivers
in my file I try include QSqlDatabase
#include <QSqlDatabase>
and in my .pro file
QT += core \
...
sql
Use Qt Creator to compile the app. What do I do wrong?
UPD: I made simple program to check which drivers are available.
#include <QtCore/QCoreApplication>
#include <QSqlDatabase>
#include <QtSQL>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
return a.exec();
}
and it works without any problems. Have no idea why it doesn't with the main app
FIXED: for some reason some files were not updated in the 'build' and 'release' folders and that is why app didn't want to find sql. removed 'build' and 'release' folders completely, build again and it works.

Compiling Qt applications from command-line in Windows

I downloaded Qt SDK and set up paths for qmake etc commands. Now I'm trying to compile "Hello World" program from command-line but don't know how to do that in Windows.
In Linux, it's very simple: qmake -project; qmake; make;
In Windows I tried: qmake -project; qmake; mingw32-make;
mingw32-make returns: "Nothing to be done for first"
Source code which I would like to compile is here:
#include <QtGui>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow mainWindow;
mainWindow.setWindowTitle("Hello World!");
mainWindow.show();
return app.exec();
}
I know that I could use Qt Creator IDE but I would like to know how to compile Qt programs in command-line.
Anybody have experiences?
"Nothing to be done" can indicate that everything was already compiled.
You can run mingw32-make clean and then mingw32-make again to check if that's the case.
Also check that the .pro file generated by qmake -project does list your .cpp file in the SOURCES variable.

Resources