I'm writing a QML application using Qt 5.7 on Ubuntu 14.04. I prefer to use an editor other than Qt Creator, so it makes it slightly cumbersome to launch Qt Creator and switch to it just to press Ctrl-R each time I want to run. I'd like to compile and launch my app from the command line.
Following this answer and then this answer I was able to install qmake and make it the default:
sudo apt-get install qt5-qmake
sudo apt-get install qt5-default
Following this answer I am copying the qmake build command listed by Qt Creator in the Project tab and successfully building the make file:
qmake qt-client.pro -r -spec linux-g++
However, when I run make (on my already-working-in-Qt-Creator code) I get:
phrogz#Slub:~/Code/rb3jay/qt-client$ make
g++ -c -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -I. -I/usr/include/qt5 -I/usr/include/qt5/QtQuick -I/usr/include/qt5/QtQml -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6:36: error: ‘AA_EnableHighDpiScaling’ is not a member of ‘Qt’
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
^
make: *** [main.o] Error 1
I'm guessing that perhaps the version of Qt being picked up by qmake or g++ is not the 5.7 version Qt Creator is using, since AA_EnableHighDpiScaling was added in Qt 5.6.
The full generated Makefile includes
99 references to /usr/include/qt5 and 179 references to /usr/lib/x86_64-linux-gnu/qt5. Qt 5.7 is installed in /home/phrogz/Qt5.7.0. Obviously I need to modify something in the qmake command to get this pointing elsewhere.
How can I get this to work? Do I need to somehow remove an older version of qt libraries installed by Ubuntu? Point some configuration to the version of Qt 5.7 that's now installed (by the Qt Installer) in my home directory? Replace existing/old Qt directories with symlinks?
Or you can use CMake:
cmake_minimum_required (VERSION 2.8.11)
project(myproject)
find_package(Qt5 5.7.0 REQUIRED COMPONENTS
Core
Quick
Widgets
)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(${PROJECT_NAME}
main.cpp
)
target_link_libraries(${PROJECT_NAME}
Qt5::Core
Qt5::Quick
Qt5::Widgets
)
Related
I'm using the jurplel/install-qt-action with itself uses aqtinstall under the covers to configure a github action to build a basic qt application against mingw53 (also tried mingw73 both win32 and win64) with obviously a windows build agent.
Build always fails on the link:
C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'D:/a/qt-github-console/qt-github-console'
g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_CORE_LIB -I. -I../Qt/5.11.3/mingw53_32/include -I../Qt/5.11.3/mingw53_32/include/QtCore -Idebug -I../Qt/5.11.3/mingw53_32/mkspecs/win32-g++ -o debug/main.o main.cpp
g++ -Wl,-subsystem,console -mthreads -o debug/qt-github-console.exe debug/main.o -LD:/a/qt-github-console/Qt/5.11.3/mingw53_32/lib D:/a/qt-github-console/Qt/5.11.3/mingw53_32/lib/libQt5Cored.a
debug/main.o: In function `main':
D:\a\qt-github-console\qt-github-console/main.cpp:5: undefined reference to `__imp__ZN16QCoreApplicationC1ERiPPci'
D:\a\qt-github-console\qt-github-console/main.cpp:7: undefined reference to `__imp__ZN16QCoreApplication4execEv'
D:\a\qt-github-console\qt-github-console/main.cpp:5: undefined reference to `__imp__ZN16QCoreApplicationD1Ev'
D:\a\qt-github-console\qt-github-console/main.cpp:5: undefined reference to `__imp__ZN16QCoreApplicationD1Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Debug:63: debug/qt-github-console.exe] Error 1
mingw32-make[1]: Leaving directory 'D:/a/qt-github-console/qt-github-console'
mingw32-make: *** [Makefile:36: debug] Error 2
The desktop QtCreator version of this minimal console app builds fine against exactly the same package versions. Have tried lots of combinations of versions and (potential) LIB/static flags but still no dice. The lack of any examples of representative mingw Qt builds on github makes me think that this is just an untested and always failing path but I am desperate to get it working! Any ideas for other thing to try? Project is here along with history of all the build failures:
https://github.com/bowniewk/qt-github-console
Ok it was pretty simple in the end but took me an age to conceptually work out.
At time of writing default windows-latest github actions agents come with mingw (8.2) and strawberryperl installed as chocolatey packages. Both of these have g++.exes (64-bit) which contaminate the path. Additionally there is no chocolatey package which I could find that does mingw 32-bit (either 5.3 or 7.3) which I could use against 32-bit Qt.
However you can uninstall the choco packages mentioned above and either go fully 64-bit or if you want 32-bit you can install the numworks/setup-msys2 action as follows:
name: CI
env:
QT_VERSION: "5.12.7"
MINGW_VERSION: "win32_mingw73"
MINGW_PATH: "mingw73_32"
on: [push]
jobs:
build:
runs-on: windows-latest
steps:
- name: Install correct version of mingw
run: |
choco uninstall mingw --force
choco uninstall strawberryperl --force
- uses: numworks/setup-msys2#v1
with:
msystem: MINGW32
- name: Install Qt
uses: jurplel/install-qt-action#v2.5.3
with:
version: ${{ env.QT_VERSION }}
arch: ${{ env.MINGW_VERSION }}
extra: --external 7z
- uses: actions/checkout#v1
[etc.]
I'm having trouble getting Qt to statically link its libraries when cross compiling from my Linux machine to windows. I added this to my config to make compile statically.
win32:CONFIG += -static
And by looking at the output of make it seems to have passed the flags correctly (omitting object files to make it short)
i686-w64-mingw32-g++ -static -static-libstdc++ -static-libgcc -Wl,-subsystem,windows -mthreads [exe and object files] /usr/i686-w64-mingw32/lib/libQt5Widgets.dll.a -ldwmapi -luxtheme /usr/i686-w64-mingw32/lib/libQt5Gui.dll.a -lopengl32 -lgdi32 -lcomdlg32 -loleaut32 -limm32 -ljpeg -lpng -L/usr/i686-w64-mingw32/lib -lfreetype -lbz2 -lharfbuzz -lm -lintl -lglib-2.0 -lshlwapi -lpcre -lgraphite2 /usr/i686-w64-mingw32/lib/libQt5Core.dll.a -lz -lpcre2-16 -liconv -lversion -lnetapi32 -luserenv -lole32 -luuid -lwinmm -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 /usr/i686-w64-mingw32/lib/libglu32.a /usr/i686-w64-mingw32/lib/libopengl32.a /usr/i686-w64-mingw32/lib/libgdi32.a /usr/i686-w64-mingw32/lib/libuser32.a -lmingw32 /usr/i686-w64-mingw32/lib/libqt5main.a -lshell32
As you can see the static flags are being passed to the compiler correctly, however I tried running the resulting exe in both WINE, and on a windows machine but in both cases it tells me that it failed to find the Qt dlls. The wine error log had more info so that's the one im providing
0009:err:module:import_dll Library Qt5Core.dll (which is needed by L"Z:\\home\\zee\\mapper\\release\\mapper.exe") not found
0009:err:module:import_dll Library Qt5Gui.dll (which is needed by L"Z:\\home\\zee\\mapper\\release\\mapper.exe") not found
0009:err:module:import_dll Library Qt5Widgets.dll (which is needed by L"Z:\\home\\zee\\mapper\\release\\mapper.exe") not found
0009:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\zee\\mapper\\release\\mapper.exe" failed, status c0000135
I'm running on an Arch Linux machine with the latest qt5base aur package (5.13.1), and the latest mignw package (g++ 9.2.0)
Your compiler command line has both static and dynamic libraries. For instance: "/usr/i686-w64-mingw32/lib/libQt5Core.dll.a" is the import library for the dynamic "Qt5Core.dll". The right file to be linked in static mode would be "libQt5Core.a". Your problem looks similar to this report of the mingw project: https://github.com/msys2/MINGW-packages/issues/4970
I'm new to Qt and have just installed the latest version of Linux (mint Ubuntu 13.04) to begin my programming. To begin with I have installed Qt4 using the github BuildScript (this also installs QtCreater, QtDesigner, QtAssistant, and QtLinguist). I have also installed PySide, as I plan to do a little Python gui programming as well. I did not consciously install qt5, but it appears, at some point along the line I did.
The following program from the QT tutorial illustrates my issue:
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
delete label;
return app.exec();
}
Now running:
..] $ qmake -project
..] $ qmake
..] $ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB
-DQT_CORE_LIB -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I.
-I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I.
-o helloWorld.o helloWorld.cpp helloWorld.cpp:1:24:
fatal error: QApplication: No such file or directory compilation terminated.
which obviously means gcc isn't finding QApplications in the libraries specified by qmake. Investigating this:
..] $ sudo find / -name QApplication*
/usr/include/qt4/QtGui/QApplication
/usr/include/qt5/QtWidgets/QApplication
/home/drk/Canopy/appdata/canopy-1.0.1.1189.rh5-x86_64/include/QtGui/QApplication
Looking in the make file, the libraries supplied are (as can be seen from the compiler line):
INCPATH = -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/qt5
-I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I.
Finally, looking at qmake:
..] $ qmake --version
QMake version 3.0
Using Qt version 5.0.1 in /usr/lib/x86_64-linux-gnu
So as you can see, qmake is assuming qt 5.0.1 despite the fact that I installed Qt4 and in my qt5 library directory hierarchy "QApplications" is located in /usr/include/qt5/QtWidgets and not in QtGui. However, qmake does not add QtWidgets/ to my include libraries.
I don't understand what has happened...can one not have qt4 and qt5 on one system at the same time?...does my qt5/qt5 installation appear corrupted?...how do I get qmake to use Qt4? Any suggestions would be greatly appreciated.
You can have both Qt 4 and 5 on the same system. However, there are little differences amongst them, and you're hitting one of those. In Qt 5, widgets now live in their own module, so you need to add
QT += widgets
to your .pro file and rerun qmake.
(And before you say that you don't see anything on screen: do not delete the label!)
See if there's a "qmake4", "qt4-qmake" or "qmake-qt4" command instead of just "qmake".
Also, why did you install Qt4 externally? Ubuntu offers it in its repositories. Just install it with Ubuntu's package manager. This way you can be sure it will be installed correctly. Qt Creator is also available in the repos.
I asked this question on the Qt forums, but they seem to be pretty quiet these days.
I'm running the relatively new Qt Creator 2.6.2 (with Qt 5.0.1). When I try to build the debugger helper, I get the following error:
Building helper(s) with toolchain 'GCC (x86 64bit)'... Building helper
'GDB helper' in
/Developer/Applications/Qt/5.0.1/clang_64//qtc-debugging-helper/
Running /Developer/Applications/Qt/5.0.1/clang_64/bin/qmake -spec
macx-clang dumper.pro -nocache CONFIG+=x86_64 ...
Running /usr/bin/make all -k ... Error running '/usr/bin/make all -k'
in /Developer/Applications/Qt/5.0.1/clang_64//qtc-debugging-helper/:
The process returned exit code 2: clang++ -c -pipe
-mmacosx-version-min=10.6 -O2 -Wall -W -fPIC -DUSE_QT_CORE=1 -DUSE_QT_GUI=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../mkspecs/macx-clang -I. -I../include -I../include/QtWidgets -I../lib/QtWidgets.framework/Versions/5/Headers -I../include/QtGui -I../lib/QtGui.framework/Versions/5/Headers -I../include/QtCore -I../lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -o dumper.o dumper.cpp make: clang++: No such file or directory make: *
[dumper.o] Error 1 make: Target `all' not remade because of errors.
Build failed.
So, I see that it's looking for a file called "clang++" which I evidently don't have. Can someone explain to me what the workaround for this is? I'm accustomed to just using the pre-built install packages for Qt.
Thanks.
You need to install command line tools package for Xcode which includes 'clang++' compiler.
You can find them here under Looking for additional developer tools? link.
I have Qt Creator installed on my Windows 7 machine and my target is an OMAP3 Embedded Linux board. I downloaded the target toolchain, Sourcery-G++ Lite for Windows, and also installed MinGW ( http://www.mingw.org/ ) on my Windows Machine. In QT Creator I added the CodeSourcery toolchain as a 'Manual' toolchain as shown in the image below. Then, I tried to build the demo Qt App 'analogclock' using this toolchain by editing 'Build Settings' under 'Projects' for the 'analogclock' demo app. But the toolchain is not available here under Build Settings as shown in the second image.
How can I achieve building this demo app, or any Qt app, from Qt Creator using the Code Sourcery Toolchain in the Build Options? I absolutely must use Windows to accomplish this ( cannot use Linux VM... ).
I believe it may have to do with building the Qt library for the target but am not sure if that is true or how to do that on Windows. I greatly appreciate your help and insight.
EDIT: New Information - need help configuring Qt Creator:
I've used the CodeSourcery toolchain to build the Qt 4.8 library with no error and I have the .so files in the /lib directory after following http://c2143.blogspot.com/?view=classic. Now I am trying to hook in the CodeSourcery compiler and built Qt 4.8 to Qt Creator so I can build an example app for the target board.
I read the following articles:
http://doc.qt.nokia.com/qtcreator-2.4/creator-project-qmake.html
http://doc.qt.nokia.com/qtcreator-2.4/creator-tool-chains.html
describing how to add a Qt version new toolchain to Qt Creator. Please see the images attached for how I've configured Qt Creator. I am using Qt Creator 2.4.1.
I'm getting an error without much information pasted below... Any thoughts on this or my configuration?
09:51:07: Running build steps for project analogclock...
09:51:07: Configuration unchanged, skipping qmake step.
09:51:07: Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
arm-none-linux-gnueabi-g++ -c -pipe -march=armv7-a -mtune=cortex-a8 -mthumb -mfpu=neon -mfloat-abi=softfp -Wa,-mimplicit-it=thumb -O2 -Wall -W -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I"..\qt-4.8-src\include\QtCore" -I"..\qt-4.8-src\include\QtNetwork" -I"..\qt-4.8-src\include\QtGui" -I"..\qt-4.8-src\include" -I"." -I"c:\QtSDK\Examples\4.7\widgets\analogclock" -I"." -I"..\qt-4.8-src\mkspecs\default" -o analogclock.obj c:\QtSDK\Examples\4.7\widgets\analogclock\analogclock.cpp
arm-none-linux-gnueabi-g++ -c -pipe -march=armv7-a -mtune=cortex-a8 -mthumb -mfpu=neon -mfloat-abi=softfp -Wa,-mimplicit-it=thumb -O2 -Wall -W -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I"..\qt-4.8-src\include\QtCore" -I"..\qt-4.8-src\include\QtNetwork" -I"..\qt-4.8-src\include\QtGui" -I"..\qt-4.8-src\include" -I"." -I"c:\QtSDK\Examples\4.7\widgets\analogclock" -I"." -I"..\qt-4.8-src\mkspecs\default" -o main.obj c:\QtSDK\Examples*\4.7\widgets\analogclock\main.cpp
C:\Users\pclass\Desktop\qt_creator_toolchain\qt-4.8-src\bin\moc.exe -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I"..\qt-4.8-src\include\QtCore" -I"..\qt-4.8-src\include\QtNetwork" -I"..\qt-4.8-src\include\QtGui" -I"..\qt-4.8-src\include" -I"." -I"c:\QtSDK\Examples\4.7\widgets\analogclock" -I"." -I"..\qt-4.8-src\mkspecs\default" c:\QtSDK\Examples\4.7\widgets\analogclock\analogclock.h -o moc_analogclock.cpp
mingw32-make.exe: *** [moc_analogclock.cpp] Error -1073741515
09:51:09: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project analogclock (target: Desktop)
When executing build step 'Make'
You need the Qt library for the target first. You can build it with CodeSourcery toolchain. Then, some tools(qmake, moc...) and library are available.
I added mingw to the path and then did a build and it succeeded. If I do a ‘file’ command on the example it gives me the following, which looks promising. Now to try it on the board.
$ file analogclock
analogclock: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped