How to configure a fresh installation of qtcreator? - c++

I'm trying to configue QtCreator with no success. I want to open an existing project. When I try to compile and run it, I get only empty black console. It looks like it compiles fine but no output.
I've installed this 32bit version:
Qt 5.2.0 for Windows 32-bit (MinGW 4.8, OpenGL, 689 MB) (Info)
When I start a new project, QtCreator wants me to run cmake. When It's done, it works fine. I can also build HelloWorld with "g++ main.cpp"
Can anyone tell me what should I do step by step? I ran out of strength. I don't know why it doesn't work.
I think it is not very important, but I'm using Win7 64bit. First, I tried to install 64bit QtCreator:
Qt 5.2.0 for Windows 64-bit (VS 2012, OpenGL, 589 MB) (Info)
But I had some problems with compilers. It looked like I didn't have them installed. I also tried an online installer and now this 32bit version. Always same result.
EDIT:
I found out something. This works:
ComputerGraphics.pro
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += C:/Users/user/Desktop/projekty/PocitacovaGrafika2/opencv/include
LIBS += -LC:\\Users\user\\Desktop\\projekty\\PocitacovaGrafika2\\opencv\\bin \
libopencv_core246d \
libopencv_highgui246d \
libopencv_imgproc246d \
SOURCES += main.cpp \
and main.cpp
#include <iostream>
int main(){
std::cout << "Hello";
return 0;
}
This even doesn't print Hello (.pro is the same as previously):
#include <iostream>
int main(){
std::cout << "Hello";
IplImage* img = cvLoad("Desert.jpg",1);
cvShowImage("img",img);
cvWaitKey(0);
return 0;
}
In debug, it complains:
The gdb process terminated unexpectedly (code 0)
During startup program exited with code 0xc0000135.

My solution:
1)
I've gone through my own tutorial on how to compile opencv for qt-creator with cmake here:
How to link opencv in QtCreator and use Qt library
(but using the latest opencv 2.4.8)
2)
I created a folder opencv on desktop.
I went into newly created opencv_bin/install and copied a folder include into the opencv on the desktop.
I continued into directory: install/x64/mingw and copied both bin and lib into opencv on the desktop.
3)
I moved the desktop/opencv directory into a working directory of my project.
i.e cut: desktop/opencv; paste: somepath/myQtProject/
4)
My .pro contains a reference like this:
INCLUDEPATH += C:/Users/user/Desktop/projekty/PocitacovaGrafika2/opencv/include
LIBS += -LC:\\Users\\user\\Desktop\\projekty\\PocitacovaGrafika2\\opencv\\bin \
libopencv_core248d \
libopencv_highgui248d \
libopencv_imgproc248d \
And in the main.cpp just #include "opencv2/opencv.hpp"
PS: I hope this will also help somebody else.

Related

How to link my app statically against ICU 57.1 MinGW

I've built ICU 57.1 statically with MinGW x32;
As a result, I got the following files in the lib directory:
libsicudt.a
libsicuin.a
libsicuio.a
libsicule.a
libsiculx.a
libsicutest.a
libsicutu.a
libsicuuc.a
sicudt.a
sicudt.dll
Now I want to run one of the examples, but whatever I try it
I receive errors like
"undefined reference to unum_...
unum_setAttribute
unum_formatInt64
u_isspace".
Total number of errors at the beginning was about 1700.
Analyzing pkgconfig files I figured out some mutual dependencies and
after reordering .a files in cmd line reduced errors to 82.
But I have no idea where to go next.
Google shows that many people have same problem with ICU but
so far there is no solution that works for me and explains the cause.
When building, I use Qt Creator for convenience, here is my .pro file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
ICUDIR=$$(ICU_PATH)
ICU_LIBPATH=$$ICUDIR"/dist/lib/"
INCLUDEPATH += $$ICUDIR"/dist/include"
LIBS += $$ICU_LIBPATH"libsicuuc.a" $$ICU_LIBPATH"libsicudt.a" \
$$ICU_LIBPATH"libsicuin.a" $$ICU_LIBPATH"libsicuio.a" \
$$ICU_LIBPATH"libsicule.a" $$ICU_LIBPATH"libsiculx.a" \
$$ICU_LIBPATH"libsicutu.a" $$ICU_LIBPATH"sicudt.a"
I have following questions:
1) Can anybody write a simple one line command that statically builds
the simpliest ICU app using g++? Is it even possible?
2) What is the correct order of .a files when passing them to linker?
3) What are files libsicudt.a, sicudt.a and sicudt.dll inteded for?
4) Is the file list I wrote above complete or my build is corrupt?
5) Is there anything I've missed of doing wrong?
Finally, I solved the problem. In order to share my experiece with you
I will describe four major pitfalls that I've encountered.
I assume that you use msys2 and MinGW-w32 if you want to repeat the steps.
Use same toolchain for everything. Note that MinGW, MinGW-w32 and MinGW-w64
are 3 different toolchains. If you have multiple installations of MinGW
like me, make sure that you use only one of them for the entire project.
I chose MinGW-w32 for compatibility reasons.
The newest versions of software often contain bugs, and they
require from you some more dancing with tambourins.
ICU v58 was buggy at the moment of writing this post.
The solution is to revert to an older version (57.1 in my case).
Before building ICU library, make sure to setup everything correctly.
Here problem is with using namespaces and renaming namespaces which
ICU does by default.
Find file C:\icu\source\common\unicode\uconfig.h and add the following
at the beginning after include guards:
#define U_DISABLE_RENAMING 1
#define U_USING_ICU_NAMESPACE 0
Save the file. Open MSYS2 terminal and set mingw-w32 as working toolset:
export PATH="/c/msys64/mingw32/bin:$PATH"
Go to icu/source dir:
cd /c/icu/source
Configure ICU for static build with no renaming and U_USING_ICU_NAMESPACE=0:
export CFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_GNUC_UTF16_STRING=1 -DU_STATIC_IMPLEMENTATION"
export CXXFLAGS="-DU_USING_ICU_NAMESPACE=0 -std=gnu++11 -DU_CHARSET_IS_UTF8=1 -DU_GNUC_UTF16_STRING=1 -DU_HAVE_CHAR16_T=1 -DUCHAR_TYPE=char16_t -Wall --std=c++11 -DU_STATIC_IMPLEMENTATION" -static-libstdc++ -fno-exceptions
export CPPFLAGS="-DU_DISABLE_RENAMING=1 -DU_CHARSET_IS_UTF8=1 -DU_STATIC_IMPLEMENTATION"
export LDFLAGS="-std=gnu++11"
./runConfigureICU MinGW prefix=$PWD/../dist -enable-static -disable-shared --disable-renaming
Build and install ICU lib. -j4 speeds up the process if you have 4 cores:
mingw32-make -j4
mingw32-make install
Cleanup intermediate files:
mingw32-make clean
Now you should have static libraries located at icu/dist/lib .
PITFALL 4: when linking statically, you should pass libraries to
linker in correct order. That matters only for static linking.
But how to figure out which order is correct?
Here pkg-config tool comes handy.
What it does is the following: takes library package names as
parameter, calculates dependencies and returns the complete string
of parameters that can be fed directly to the compiler
or viewed by you to understand what's going on under the hood.
There are 5 packages located at C:\icu\dist\lib\pkgconfig.
Let's configure path for pkg-config:
export PKG_CONFIG_PATH="/c/icu/dist/lib/pkgconfig:$PKG_CONFIG_PATH"
In order to test it, type:
pkg-config --static --cflags --libs icu-uc icu-i18n icu-io icu-le icu-lx
The output should be:
-IC:/icu/dist/include -LC:/icu/dist/lib -lsicuio -lsicuin -lsiculx -lsicule -lsicuuc -lsicudt -lpthread -lm
That's the string we have to pass to compiler.
As final test, we will compile a simple example app using command line:
Create folder /c/icu/dist/test with file test.cpp inside:
#include <unicode/unistr.h>
#include <unicode/ustdio.h>
#include <unicode/brkiter.h>
#include <stdlib.h>
using namespace icu;
void printUnicodeString(UFILE *out, const UnicodeString &s) {
UnicodeString other = s;
u_fprintf(out, "\"%S\"", other.getTerminatedBuffer());
}
int main( void )
{
UFILE *out;
UErrorCode status = U_ZERO_ERROR;
out = u_finit(stdout, NULL, NULL);
if(!out) {
fprintf(stderr, "Could not initialize (finit()) over stdout! \n");
return 1;
}
ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE,
NULL, NULL, NULL, &status);
if(U_FAILURE(status)) {
u_fprintf(out, "Warning- couldn't set the substitute callback - err %s\n", u_errorName(status));
}
/* End Demo boilerplate */
u_fprintf(out,"ICU Case Mapping Sample Program\n\n");
u_fprintf(out, "C++ Case Mapping\n\n");
UnicodeString string("This is a test");
u_fprintf(out, "\nstring: ");
printUnicodeString(out, string);
string.toUpper(); /* string = "THIS IS A TEST" */
u_fprintf(out, "\ntoUpper(): ");
printUnicodeString(out, string);
return 0;
}
Go to the test dir:
cd /c/icu/dist/test
g++ -o test test.cpp \
`pkg-config --cflags --libs --static icu-uc icu-i18n icu-io icu-le icu-lx`
Run the app:
./test
Maybe this is not the best way to do,
especially concerning workspaces, but it works.
More about pgk-config here:
https://people.freedesktop.org/~dbn/pkg-config-guide.html

When compiling get error: 'QtGui/QAction' file not found #include <QtGui/QAction>

I just installed Mac OS X 10.8.3 and Qt Creator 3, XCode, and XCode command line tools. I'm trying to compile a project that works on another computer but each time I go to "build all" I get error: 'QtGui/QAction' file not found
in #include <QtGui/QAction>
I tried adding the second and third line in the .pro file but it didn't help
QT += core gui opengl
CONFIG += qt
QT += gui
TARGET = BasicOpenGL
TEMPLATE = app
UPDATE: I also tried this .pro file and it didn't work
QT += core gui opengl
QT += widgets
TARGET = BasicOpenGL
TEMPLATE = app
I should say this is my first time attempting development on mac.
Compile Output from Qt
Versions/A/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I. -F/Users/john/Qt/5.2.0/clang_64/lib -o mainwindow.o ../Framework/mainwindow.cpp
In file included from ../Framework/mainwindow.cpp:2:
../Framework/ui_mainwindow.h:14:10: fatal error: 'QtGui/QAction' file not found
#include <QtGui/QAction>
^
1 error generated.
make: *** [mainwindow.o] Error 1
15:51:32: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project BasicOpenGL (kit: Desktop Qt 5.2.0 clang 64bit)
When executing step 'Make'
UPDATE: I got it to work but with all the screwing around I'm not exactly sure what did it. I started with a fresh mac image, installed system updates, installed xcode, installed xcode command line tools, installed QT Creator 3.0, installed QT libraries 4.8.1, setup the compilers in QT Creator.
Try doing a make clean followed by a make. I had this exact problem on a Windows 7 system, and this is what worked for me.
In Qt5, QAction header is in QtWidgets include sub-directory, not in QtGui (that's true for Qt4). Though you don't actually need to specify include sub-directories since qmake will handle that for you. You just need to add QT += widgets to your .pro file.
Set the version to Qt5, change all #include<QtQui/*>s into #include<QtWidgets/*>.
And add QT += widgets in your .pro file.
Rebuild the project, when you get the error again, tap into the error message, and change the #include<QtQui/*>s into #include<QtWidgets/*> too.
Some answers here say that you have to change include from <QtGui/QAction> to <QtWidgets/QAction>.
It was the case when you compile under QT-5. But after QT-6 was released you have to do the opposite in QT-6 application.
Now you have to change <QtWidgets/QAction> to <QtGui/QAction>, because now QAction is located in QtGui folder in QT-6.
Although my answer is not related to your very old question, as you had QT-4 problem, still your question pops up first in Google hence I'm posting my answer for those StackOverflow visitors who have same problem but with compiling QT-5 project under QT-6, as I did.

"Can't load OpenGL extension [glBindBuffer] in function IntGetProcAddress" exception of OpenCV in Qt

I downloaded OpenCV 2.4.6 from the opencv website. To avoid the problem I mentioned before, I decided to compile the OpenCV library. After CMake and Mingw32-make, the compile succeeded. However, a simple test program crashes when tring to show a jpeg image. Here is my .pro and main.cpp file:
.pro:
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
#INCLUDEPATH += D:/opencv2.4.6/build/include
INCLUDEPATH += D:/opencv2.4.6/release/install/include
LIBS += -LD:/opencv2.4.6/release/install/bin \
-lopencv_core246 \
-lopencv_highgui246 \
-lopencv_imgproc246 \
-lopencv_features2d246 \
-lopencv_calib3d246
main.cpp:
int main() {
Mat input = imread("Z:/1.jpg");
cv::imshow("1.jpg",input);
}
Here is the problem:
OpenCV Error: OpenGL API call (Can't load OpenGL extension [glBindBuffer]) in In
tGetProcAddress, file ..\..\..\modules\core\src\gl_core_3_1.cpp, line 141
terminate called after throwing an instance of 'cv::Exception'
what(): ..\..\..\modules\core\src\gl_core_3_1.cpp:141: error: (-219) Can't lo
ad OpenGL extension [glBindBuffer] in function IntGetProcAddress
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I've never encountered such problem before. It's kind of weird. What should I do to get rid of this problem?
After trying to compile OpenCV, it seems that the WITH_OPENGL should be unchecked. Now the program runs normally.

Qt Creator + OpenCV: Program runs from .exe but not from editor

Well, I need to start working with OpenCV and as I'm used to working with QtCreator, I'm trying to make it all work together. I downloaded the latest OpenCV version, and compiled it with MinGW. Then, I created this little console project to try it out. Below is the .pro file:
QT += core
QT -= gui
TARGET = OpenCV_test4
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\\Librerias\\opencv2.3.1\\release\\include
LIBS += -LC:\\Librerias\\opencv2.3.1\\release\\lib \
-lopencv_core231.dll \
-lopencv_highgui231.dll \
-lopencv_imgproc231.dll \
-lopencv_features2d231.dll \
-lopencv_calib3d231.dll
Here is the main.cpp file:
#include <QtCore/QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// read an image
cv::Mat image= cv::imread("img.jpg");
// create image window named "My Image"
cv::namedWindow("OpenCV Window");
// show the image on window
cv::imshow("OpenCV Window", image);
// wait key for 5000 ms
cv::waitKey(5000);
return a.exec();
}
(I have tried this code with and without the QCoreApplication lines)
The deal is: It links and builds, and when runs from QtCreator only a terminal window called C:\QtSDK\QtCreator\bin\qtcreator_process_stub.exe appears with the line "Press RETURN to close this window..."
But, if I run the .exe from the project folder, it runs perfectly!! Why is QtCreator unable to launch the application? I found this really strange, and I would appreciate any hint about this. It's really not THAT important, but it is kind of a pain to have to run the .exe manually every time I change something to check how it works.
Thanks for your time :)
Additional Info:
I have tried both debug and release versions, the problem is the same in both of them.
Debugging does not work, it never stops at any breakpoint.
I'm running on Windows 7 Proffesional x64
SOLVED, I don't really know what I did, it suddenly worked and keeps working, I wish I could tell you how I fixed it but I have no idea, such a weird thing :(
Check Projects -> Run Settings -> Run in terminal. It have to be enabled, but seems to be disabled.
I have met same problem with QtCreator and OpenCL under Linux. Simple test program works after start from terminal and it does not work after start from the QtCreator.
I found the cause was hardcoded LD_LIBRARY_PATH in the project's run environment settings. I had dropped it to empty string and this had fixed issue.
I had the same issue with the following environment: Raspbian, Qt, openCV and a gui application.
old-ufo recommendation worked for me:
- First, enable "Run in terminal", which failed
- Then, disable "Run in terminal", which allowed me to correctly debug my app.
I understand that this is not scientific.

How to call Carbon function from Qt Creator project?

I'm trying to use ChangeWindowAttributes() function in Qt Creator project on Mac OS X.
But I can't build the project.
What I've tried:
#include <MacWindows.h>
Result (compiler): File not found
#include <Carbon/Carbon.h>
// Or the same:
#include </Developer/Headers/FlatCarbon/MacWindows.h>
Result (compiler): ChangeWindowAttributes was not declared in this scope
#include <Carbon/Carbon.h>
extern OSStatus ChangeWindowAttributes (
WindowRef window,
WindowAttributes setTheseAttributes,
WindowAttributes clearTheseAttributes
);
// And in *.pro file:
LIBS += -framework Carbon
Result (linker): Undefined Symbols ChangeWindowAttributes( ...
Where am I wrong?
According Google it seems that everybody already knows how to include it, so there are no guides anywhere. Maybe someone here also has a link to the guide or something?
By default, QT Creator build your project in your Mac's CPU architecture. The libraries themselves come in x86 and x86_64 universal binaries. This is if you are using the prebuild SDK from Nokia.
If you are running 64-bit capable OS/Mac combination, like 10.6 on a new Intel Mac, it will build it in x86_64. Carbon calls are still available to your code but only those marked as 64-bit compatible one. Open MacWindows.h and find ChangeWindowAttributes. You will see in the comment:
* Availability:
* Mac OS X: in version 10.0 and later in Carbon.framework [32-bit only]
* CarbonLib: in CarbonLib 1.0 and later
* Non-Carbon CFM: not available
If you have to call this (and other 32-bit only) function, you'll have to force Creator to build it in 32-bit (x86). Add these lines to your .pro file:
CONFIG -= x86_64
CONFIG += x86
Clean all and rebuild.