qmake doesn't invoke uic - c++

I'm aware that there is a couple of questions asked online on similar issues but unfortunately none of them helped me solving this relatively simple-looking one, as the title suggests.
I set up a minimal Qt project in which the problem occurs:
├── main.cpp
├── mainwindow.ui
└── qt.pro
main.cpp:
#include <QtWidgets/QtWidgets>
#include "ui_mainwindow.h"
int main () {
return 0;
}
qt.pro:
TEMPLATE = app
TARGET = qt-qmake-uic-problem
INCLUDEPATH += .
# Input
FORMS += mainwindow.ui
SOURCES += main.cpp
The file mainwindow.ui is the default MainWindow Form provided by Qt Creator.
Now if I run
qmake qt.pro
then a Makefile is created causing this error when make gets executed:
[developer#kdb qt-qmake-uic-problem]$ make
g++ -c -pipe -O2 -march=i686 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -I/usr/lib/qt/mkspecs/linux-g++ -o main.o main.cpp
main.cpp:2:28: fatal error: ui_mainwindow.ui: No such file or directory
#include "ui_mainwindow.h"
^
compilation terminated.
make: *** [Makefile:298: main.o] Error 1
According to my best knowledge ui_mainwindow.h must be generated either by qmake or by the Makefile - not by myself invoking uic manually. I must note that something similar happens with moc as well and doing my research I haven't found an explanation neither in the documentation nor in similar issues, although it would be strange if this installation of qmake were broken - I'm running Arch Linux and got Qt SDK from the default repository.
Thank you very much for your help in advice!

Assuming you are using QT-5:
If you want to use UI elements linke a QMainWindow or other QT widgets, you need to enable widgets generally in your project configuration:
QT += widgets
This then activates the processing of the FORMS content like mainwindow.ui in your example, and causes that your code gets linked with the correct libraries.
See also here: http://doc.qt.io/qt-5/qtwidgets-index.html

Related

Building SWipe Application

I'm currently trying to build this application https://github.com/ieatlint/SWipe on macOS and am not having any luck. I don't know much about building applications but this is what I have done so far.
git clone https://github.com/ieatlint/SWipe
cd SWipe
qmake SWipe.pro
make
And that's where I get an error:
make
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -O2 -std=gnu++11 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.10 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_MULTIMEDIA_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I/usr/local/Cellar/qt/5.9.1/lib/QtMultimedia.framework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtWidgets.framework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtGui.framework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtNetwork.framework/Headers -I/usr/local/Cellar/qt/5.9.1/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.9.1/mkspecs/macx-clang -F/usr/local/Cellar/qt/5.9.1/lib -o main.o main.cpp
main.cpp:1:10: fatal error: 'QtGui/QApplication' file not found
#include <QtGui/QApplication>
^
1 error generated.
make: *** [main.o] Error 1
I tried adding QT += widgets to the SWipe.pro file by using sudo nano SWipe.pro and adding it under where it says QT += core gui multimedia, but that didn't work.
I just cloned it quickly and had a look. Here is what's wrong with the code:
add widgets to the pro file as you already did (run qmake after this again)
in main.cpp change the include from QtGui/QApplication to just Application (as suggested by AlexanderVX)
Do the same in swipe.h for QtGui/QMainWindow and change it to just QMainWindow
in swipe.cpp change audioFormat.setFrequency( 48000 ) to audioFormat.setSampleRate( 48000 ), assuming that is what it should do as there is no setFrequency function
in swipe.cpp change audioFormat.setChannels( 1 ) to audioFormat.setChannelCount( 1 ), assuming that is what it should do as there is no setChannels function
I did this on my Mac and it builds this way. Have not run it though as I have not really looked into what this thing is doing... that's your job now I guess

qmake with Jenkins

I am trying to make Jenkins do the compile and build for me whenever I push commit to Git. I have a helloworld app created in Qt Creator. It does compile and build in Qt Creator, it does show on my phone, but it doesn't want to compile and build with Jenkins.
I am using the same shell commands which QtC used:
qmake helloworld.pro -r -spec android-g++;
make;
The console output is:
+ qmake helloworld.pro -r -spec android-g++
+ make
/home/ndk/toolchains/arm-linux-androideabi-4.9-/prebuilt/bin/arm-linux-androideabi-g++ -c -pipe -std=c++11 -O2 -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -I/usr/share/qt4/mkspecs/android-g++ -I. -I. -I/home/ndk/sources/cxx-stl/gnu-libstdc++//include -I/home/ndk/sources/cxx-stl/gnu-libstdc++//libs//include -I/home/ndk/platforms//arch-arm//usr/include -o main.o main.cpp
In file included from main.cpp:1:0:
mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
#include <QMainWindow>
^
compilation terminated.
Makefile:187: recipe for target 'main.o' failed
make: *** [main.o] Error 1
My helloworld.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = helloworld
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
CONFIG += mobility
MOBILITY =
main.cpp
#include "mainwindow.h"
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
EDIT/UPDATE:
So far, I have tried to specify the full path to qmake, to be sure that I use Qt's qmake.
/home/qt/5.7/android_armv7/bin/qmake helloworld.pro -r -spec android-g++;
make;
The output is:
/home/qt/5.7/android_armv7/bin/uic mainwindow.ui -o ui_mainwindow.h
/home/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -c -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -fno-builtin-memmove -std=c++11 -O2 -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../qt/5.7/android_armv7/include -I../../qt/5.7/android_armv7/include/QtWidgets -I../../qt/5.7/android_armv7/include/QtGui -I../../qt/5.7/android_armv7/include/QtCore -I. -I. -I../../ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -I../../ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -I../../ndk/platforms/android-9/arch-arm/usr/include -I../../qt/5.7/android_armv7/mkspecs/android-g++ -o main.o main.cpp
/home/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -c -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -fno-builtin-memmove -std=c++11 -O2 -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -Wall -Wno-psabi -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../qt/5.7/android_armv7/include -I../../qt/5.7/android_armv7/include/QtWidgets -I../../qt/5.7/android_armv7/include/QtGui -I../../qt/5.7/android_armv7/include/QtCore -I. -I. -I../../ndk/sources/cxx-stl/gnu-libstdc++/4.9/include -I../../ndk/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -I../../ndk/platforms/android-9/arch-arm/usr/include -I../../qt/5.7/android_armv7/mkspecs/android-g++ -o mainwindow.o mainwindow.cpp
mainwindow.cpp:3:25: fatal error: QtGui/QAction: No such file or directory
#include <QtGui/QAction>
^
compilation terminated.
Makefile:1780: recipe for target 'mainwindow.o' failed
make: *** [mainwindow.o] Error 1
Most likely your jenkins setup uses the wrong qmake. There's a 1:1 mapping between a Qt installation and its qmake. So, your install of Qt for android will have its own qmake that you must refer to by full path! Qt Creator sets up the path so that this happens automatically, Jenkins doesn't - and it shouldn't anyway.
When building for any particular Qt version, you only need to invoke its qmake explicitly. From then onwards, as long as the proper compiler is in the path, things will happen as they should and you don't ever need to refer to that Qt version manually again. The makefiles will all refer to Qt libraries, headers and tools from that Qt install.
You also don't need the -spec argument. Each Qt installation is compiled for a particular mkspec, so qmake itself knows exactly what the spec is. I have no idea why QtCreator gives that argument, it doesn't make much sense.
The only Qt header path that's in your commandline is the one for the mkspec. I would blame the server's Qt installation for this.
Ensure Qt for Android is properly installed on the server, and that it is its qmake you are calling.

Travis CI QT not building

So I wanted to use travis for this project today. Sadly it failed with this error:
$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/qt5 -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o downloadmanager.o downloadmanager.cpp
In file included from downloadmanager.h:11:0,
from downloadmanager.cpp:1:
mainwindow.h:4:23: fatal error: QMainWindow: No such file or directory
compilation terminated.
make: *** [downloadmanager.o] Error 1
The command "make" exited with 2.
Here is the full log.
Note I first had problems with it not recognizing the Network module file (e.g. QNetworkAccessManager). I fixed this by executing QMake with "QT += network". Now it cannot find the GUI files (e.g. QMessageBox) but adding "QT += network gui" did not do the trick.
You need to add widgets to get classes such as QMessageBox and QMainWindow:
QT += widgets network gui
For future reference, please consult the Qt 5 documentation. The page for each class indicates what must be added to your qmake for that class (right at the top of the page). See, for example, the page for QMessageBox.

Poco C++ using Raspberry Pi and Qt

Is it possible to compile Poco libs such that I can use them on Raspberry Pi with my Qt project? Currently I have my Qt project up and running on Raspberry Pi except for the functions using Poco. I thought that I could compile Poco directly on Raspberry Pi and just copy the compiled libs and header files to my Ubuntu machine, which does the compiling of my Qt project. I included
INCLUDEPATH += /path/to/poco/libs/compiled/for/raspberrypi/include
DEPENDPATH += /path/to/poco/libs/compiled/for/raspberrypi/include
LIBS += -L/path/to/poco/libs/compiled/for/raspberrypi -lPocoFoundation -lPocoNet
target.path = /home/pi/path/to/my/executable
INSTALLS += target
in my .pro file.
But I get the following error the first time the compiler encounters a Poco include:
/home/jon/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++ -c -pipe -marm -mfpu=vfp -mtune=arm1176jzf-s -march=armv6zk -mabi=aapcs-linux -mfloat-abi=hard --sysroot=/mnt/rasp-pi-rootfs -g -std=c++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_PLUGIN -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/local/qt5pi/mkspecs/devices/linux-rasp-pi-g++ -I../../../BeatQtPlayer/src/pocowebserverplugin -I../../../BeatQtPlayer/src -I/home/jon/tmp/BeatQtPlayer/src/pocowebserverplugin/../../external_tools/poco-1.4.6p2/lib_raspberrypi/include -I/mnt/rasp-pi-rootfs/usr/local/qt5pi/include -I/mnt/rasp-pi-rootfs/usr/local/qt5pi/include/QtNetwork -I/mnt/rasp-pi-rootfs/usr/local/qt5pi/include/QtCore -I. -I. -o pocowebserverplugin.o ../../../BeatQtPlayer/src/pocowebserverplugin/pocowebserverplugin.cpp
In file included from ../../../BeatQtPlayer/src/pocowebserverplugin/pocowebserverplugin.h:5:0,
from ../../../BeatQtPlayer/src/pocowebserverplugin/pocowebserverplugin.cpp:1:
../../../BeatQtPlayer/src/pocowebserverplugin/requesthandler.h:4:48: fatal error: Poco/Net/HTTPRequestHandlerFactory.h: No such file or directory
compilation terminated.
Ensure that you have set up your include paths for the Poco library itself correctly. Poco internal headers may need other directories than the root '/path/to/.../include/' path to be included into the include path.
These are the include paths your compiler is looking at. Is Poco/Net in there somewhere?
-I/usr/local/qt5pi/mkspecs/devices/linux-rasp-pi-g++
-I../../../BeatQtPlayer/src/pocowebserverplugin
-I../../../BeatQtPlayer/src
-I/home/jon/tmp/BeatQtPlayer/src/pocowebserverplugin/../../external_tools/poco-1.4.6p2/lib_raspberrypi/include
-I/mnt/rasp-pi-rootfs/usr/local/qt5pi/include
-I/mnt/rasp-pi-rootfs/usr/local/qt5pi/include/QtNetwork
-I/mnt/rasp-pi-rootfs/usr/local/qt5pi/include/QtCore
-I.
-I.

Error using Qt 5.1.1 in code::blocks

I am trying to combine Code::Blocks IDE and Qt 5.1.1 on my win7 32bit. In CB I use MinGW's g++ compiler which supports C++0x.
I downloaded "qt-windows-opensource-5.1.1-mingw48_opengl-x86-offline.exe" and installed at "D:\Qt-library\5.1.1\mingw48_32\".
Then in CB I added three tools named "qmake -project" , "qmake" and "make" at Tools->Configure tools->add.
"qmake -project" with Executable "D:\Qt-library\5.1.1\mingw48_32\bin\qmake.exe", Parameters: "-project -platform win32-g++"
"qmake" with Excutable same as "qmake -project", no parameter;
"make" with Excutable "D:\Qt-library\Tools\mingw48_32\bin\mingw32-make.exe", no parameter
Working directory all set to "${PROJECT_DIR}"
And I clicked project->properties, selected "This is a custom Makefile"
Then I clickd the "qmake -project" menu item in Tools menu which I created as above, qmake generated a .pro file.
Because I use
#include <QApplication>
instead of
#include <QtGui/QApplication>
in main.cpp file so I added "QT += widgets" in the .pro file.
Then click "qmake" in Tools menu, makefiles are generated. If I directly make, it won't compile, because it doesn't support some C++11 grammars,
so I edited the Makefile.Debug and makefile.Release, it looks like:
CC = gcc
CXX = g++
DEFINES = -DUNICODE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN
CFLAGS = -pipe -fno-keep-inline-dllexport -O2 -Wall -Wextra $(DEFINES)
CXXFLAGS = -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads $(DEFINES)
I added -std=c++0x at the line CXXFLAGS, so it become
CXXFLAGS = -pipe -std=c++0x -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads $(DEFINES)
(it won't work for my version of MinGW if I use -std=c++11)
Then click "make" in the Tools menu, I get two errors:
I don't know what the hell was that but some how I modified my main function from
int main(int argc, char** argv)
to int qMain(int argc, char** argv). Then make again, the two qMain error disappeared but I got this:
And now, I didn't do any thing, make again, that error disappeared !!!
But generated .exe file won't do anything, either double click or run in command line, nothing would happen (by the way, although I included , I didn't write any Qt code)
If I remove
#include <QApplication>
and build the project in normal way(cancel "This is a custom Makefile" and build directly), my program goes well.
Another thing very weird, I added CONFIG += debug and CONFIG -= release in the .pro file, qmake will generate both Makefile.Debug and Makefile.Release(whatever CONFIG or debug and release is uper or lower case), but generated .o files and .exe files are all in release directory, no debug file, why was that ?
Anyone has any ideas ? I'll be very thankful for your suggestions.
The problem is solved(although not perfectly).
The fact is that the program did do something, but somehow no console window appear(before I add Qt header, I wrote the program in C++ and use cout to print messages), thus no output can be seen, even if I run the program in console. I found this by writing a simple Qt GUI program to print the results, it works. But I don't know the reason why console wouldn't appear with QApplication included but no Qt code in the program (whatever I set project->properties->build targets->select build target options->type to GUI or console).
On the other hand, I can run the Qt GUI program by double clicking the .exe file in the debug directory, but not in Code::Blocks, it pops up "cannot locate program entry InterlockedCompareExchange#12 on dynamic link library libstdc++-6.dll". Thus I can't debug the program through CB.