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.
Related
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
)
1. Issue
I was trying to compile an Rcpp program with a user-defined .hpp header file following an example in http://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf, p9, section 2.10.2. It compiles nicely in RStudio on my Mac and works well.
However, when I run exactly the same program on my Windows 64-bits laptop (Win 7), I get the following error message:
g++ -m64 -I"G:/R-32~1.3/include" -DNDEBUG -I"G:/R-3.2.3/library/Rcpp/include" -I"F:/_tst/rcpp" -I"d:/RCompile/r-compiling/local/local323/include" -O2 -Wall -mtune=core2 -c tst4.cpp -o tst4.o
G:\Rtools\gcc-4.6.3\bin\nm.exe: 'F:_tstrcpputilities.o': No such file
g++ -m64 -shared -s -static-libgcc -o sourceCpp_1.dll tmp.def F:_tstrcpputilities.o tst4.o -Ld:/RCompile/r-compiling/local/local323/lib/x64 -Ld:/RCompile/r-compiling/local/local323/lib -LG:/R-32~1.3/bin/x64 -lR
g++.exe: error: F:_tstrcpputilities.o: No such file or directory
Error in sourceCpp("tst4.cpp") : Error occurred building shared library.
It seems like the slashes in the file paths are lost (I assume instead of 'F:_tstrcpputilities.o', it should be 'F:\_tst\rcpp\utilities.o'?), but I have no idea how to fix this...
2. Tentative solution but unsuccessful
I tried adding my Rtools and Rtools/gcc-x.x.x/bin directory to PATH by using devtool as follows:
add_path("G:\\Rtools");
add_path("G:\\Rtools\\bin");
add_path("G:\\Rtools\\gcc-4.6.3\\bin");
Unfortunately it did not help. The same error remains.
So...
Well, I'm stuck here... Any help would be appreciated.
=========================================================================
S1. Supplementary info
Some information about my laptop/R/Rtools:
OS: Win 7 64-bits
R version: 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Rtools version: Rtools3.3
The test cpp code (filename: tst4.cpp) I used was:
#include <Rcpp.h>
#include "utilities.hpp"
using namespace Rcpp;
// [[Rcpp::export]]
double timesTwenty(double x) {
return timesTwo(x) * 10;
}
All .cpp and .hpp files are in the same folder.
I am trying to build my Qt project with C++11 standard. I added this flag in the build steps, additional argument option, in the Qt Creator :
-std=c++11
But I got this error while building :
Unknown option -std=c++11
g++ version info : g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Any ideas ?
Use the qmake project file, add this line: QMAKE_CXXFLAGS += -std=c++11
LE: also 4.6.3 might not support C++11 (as far as i know 4.7 and higher support -std=c++11) so the option for the 0x features implemented might be: QMAKE_CXXFLAGS += -std=c++0x
If you are using Qt5, add CONFIG += c++11 to your .pro file, that works on all systems.
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