Using Qt K* classes with CMake - qt

My standard CMakeLists.txt file for projects that use Qt looks like:
PROJECT(KFileWidgetDemo)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
QT4_WRAP_UI(UISrcs form.ui)
QT4_WRAP_CPP(MOCSrcs form.h)
include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(KFileWidgetDemo main.cpp form.h form.cpp ${MOCSrcs} ${UISrcs})
TARGET_LINK_LIBRARIES(KFileWidgetDemo ${QT_LIBRARIES})
However, I have always only used Q* classes. Now I need to use KFileWidget, and I am getting errors when compiling:
error: stray ‘\177’ in program
error: stray ‘\1’ in program
Is there a magic CMake command that might fix this?
Thanks,
David

I was under the impression the the K* classes were what Qt named their KDE specific subclasses. I guess that is not quite the case. I got this working by including and linking to KDE4 directly with:
cmake_minimum_required(VERSION 2.6)
PROJECT(KFileWidgetDemo)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
find_package(KDE4 4.5.0 REQUIRED)
include_directories( ${KDE4_INCLUDES} )
QT4_WRAP_UI(UISrcs form.ui)
QT4_WRAP_CPP(MOCSrcs form.h)
include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
ADD_EXECUTABLE(KFileWidgetDemo main.cpp form.h form.cpp ${MOCSrcs} ${UISrcs})
TARGET_LINK_LIBRARIES(KFileWidgetDemo ${QT_LIBRARIES} ${KDE_LIBRARIES} ${KDE4_KDEUI_LIBS} ${KDE4_KFILE_LIBS})
Note the key to resolve the linker errors for KUrl was ${KDE4_KFILE_LIBS}.

I had a similar effect when one of my source files was converted to UTF-16 by some IDE. Check the encoding of your files and change them to UTF-8.

Related

Intel oneAPI dpcpp compiler with google test

I'm kinda new to the world of Intel's HPC toolchain and I'm facing some troubles making even simple DPC++ application to work when gtest is used as a testing framework
This is the CMakeLists "structure" I'm following
cmake_minimum_required(VERSION 3.14)
project(foo)
set(CMAKE_CXX_COMPILER "dpcpp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3 -fsycl")
# add executables
# target linked libraries
# ...
option(ENABLE_TESTS ON)
if(ENABLE_TESTS)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_subdirectory(tests)
endif()
If I remove the last block, it compiles and runs as expected, otherwise I get the following error:
CMake Error at build/_deps/googletest-src/CMakeLists.txt:10 (project):
The CMAKE_CXX_COMPILER:
dpcpp
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/u141905/foo/build/CMakeFiles/CMakeOutput.log".
See also "/home/u141905/foo/build/CMakeFiles/CMakeError.log".
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= /usr/bin/c++
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
make: *** [Makefile:2: all] Error 1
Please notice that dpcpp is correctly set, in fact I'm using Intel's devcloud platform.
Setting CXXto the output of whereis dpcpp produces the same error.
The only "workaround" (I doubt it is one though) I found is using clang++ instead (the version from Intel's llvm). Any help or suggestion is much appreciated, thanks in advance!
EDIT: after some more attempts, I noticed that if I set CMAKE_CXX_COMPILER just after fetching gtest, everything works fine. Anyway I don't understand why this happens and how can be properly fixed.
Use the path for dpcpp binary for setting the CMAKE_CXX_COMPILER instead of using"set(CMAKE_CXX_COMPILER "dpcpp")". After adding the path("/opt/intel/oneapi/compiler/2022.0.1/linux/bin/dpcpp") to the CMAKE_CXX_COMPILER, you can run the program successfully.
Please find the below CMakeLists.txt for setting the CMAKE_CXX_COMPILER:
project(foo)
set(CMAKE_CXX_COMPILER "/opt/intel/oneapi/compiler/2022.0.1/linux/bin/dpcpp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3 -fsycl")
# add executables
# target linked libraries
# ...
set(ENABLE_TESTS ON)
include(FetchContent)
if(ENABLE_TESTS)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_subdirectory(tests)
endif()
Thanks & Regards,
Hemanth
Did you run the source /opt/intel/oneapi/setvars.sh intel64 script? I.e. is dpcpp on your path before running cmake?

Crosscompile qt6 for raspberry pi 4

I have read this qt6 doc, so I start to play with this, but maybe the docs leaks some infos and the configure step fails quickly with this error:
CMake Error at cmake/QtBaseConfigureTests.cmake:21 (message):
Failed to compile architecture detection file.
Call Stack (most recent call first):
cmake/QtBaseConfigureTests.cmake:120 (qt_run_config_test_architecture)
cmake/QtBaseConfigureTests.cmake:133 (qt_run_qtbase_config_tests)
CMakeLists.txt:68 (include)
My cmake command is here:
'/usr/local/bin/cmake' '-DQT_HOST_PATH=/opt/qt6/6.0.1/gcc_64' '-DCMAKE_TOOLCHAIN_FILE=/home/mattia/raspi4-qt6/qt-cross/toolchain.cmake' '-DQT_BUILD_TOOLS_WHEN_CROSSCOMPILING=ON' '-DCMAKE_INSTALL_PREFIX=/usr/local/qt_v6.0.1' '-DCMAKE_STAGING_PREFIX=/home/mattia/raspi4-qt6/build/qt_v6.0.1' '-DQT_BUILD_EXAMPLES=FALSE' '-DQT_BUILD_TESTS=FALSE' '-DCMAKE_BUILD_TYPE=Release' '-DINPUT_opengl=es2' '-DINPUT_eglfs=ON' '-G' 'Ninja' '/home/mattia/raspi4-qt6/src/qtbase
While mine toolchaine.cmake is here:
cmake_minimum_required(VERSION 3.18)
include_guard(GLOBAL)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv8)
set(TARGET_SYSROOT /home/mattia/raspi4-qt6/sysroot)
set(CROSS_COMPILER /home/mattia/raspi4-qt6/tools/cross-pi-gcc-10.2.0-2/bin)
set(CMAKE_SYSROOT ${TARGET_SYSROOT})
set(CMAKE_C_COMPILER ${CROSS_COMPILER}/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${CROSS_COMPILER}/arm-linux-gnueabihf-g++)
set(ENV{PKG_CONFIG_PATH} "")
set(ENV{PKG_CONFIG_LIBDIR} ${CMAKE_SYSROOT}/usr/lib/arm-gnueabihf/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig)
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
The doc you linked worked properly for me. I added some more notes here: https://bugfreeblog.duckdns.org/2021/09/qt-6-on-raspberry-pi-on-eglfs.html. Maybe you can try with the toolchain I linked in the article.
I suppose that you are using Cygwin. I had same problem with cygwin, because ARM compiler not understand cygwin path /cygdrive/d/cygwin/home.....
For crosscompile qt6 on windows host use windows cmake and windows CMD. Cygwin is not needed..

Sudden memcopy warnings from QBrush after system update when compiling my program

I have no idea why this is happening. But everytime I compile my application with a couple of the Qt versions that I have installed I now get these warnings:
In file included from /home/Qt5.9.2/5.9.2/gcc_64/include/QtGui/qbrush.h:50,
from /home/Qt5.9.2/5.9.2/gcc_64/include/QtGui/qpalette.h:46,
from /home/Qt5.9.2/5.9.2/gcc_64/include/QtWidgets/qwidget.h:48,
from /home/Qt5.9.2/5.9.2/gcc_64/include/QtWidgets/qdesktopwidget.h:44,
from /home/Qt5.9.2/5.9.2/gcc_64/include/QtWidgets/QDesktopWidget:1,
from ../src/../../CommonClasses/SQLConn/../../CommonClasses/common.h:6,
from ../src/../../CommonClasses/SQLConn/dbinterface.h:10,
from ../src/../../EyeExperimenter/src/sslclient/sslclient.h:10,
from ../src/../../EyeExperimenter/src/sslclient/ssldbclient.h:4,
from ../src/sslwrapper.h:6,
from ../src/main.cpp:3:
/home/Qt5.9.2/5.9.2/gcc_64/include/QtGui/qtransform.h: In member function ‘QTransform& QTransform::operator=(QTransform&&)’:
/home/Qt5.9.2/5.9.2/gcc_64/include/QtGui/qtransform.h:81:46: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘class QTransform’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
{ memcpy(this, &other, sizeof(QTransform)); return *this; }
^
/home/Qt5.9.2/5.9.2/gcc_64/include/QtGui/qtransform.h:57:20: note: ‘class QTransform’ declared here
class Q_GUI_EXPORT QTransform
Can any one tell me what this warning is and, more importantly, how do I get rid of it? From what I've seen it has to do with gcc8 which my system currently has, however I've tried chaging the compiler in the Qt Kits configuration of QtCreator and the warning still appears...
You use qmake as the build system generator, and then gnu make to actually build stuff - Qt Creator is just a shortcut from typing it all out on the command line :)
You can pass the relevant flag to the compiler by adding the following to your .pro file, then re-running qmake on the project (e.g. delete the build folder and build again):
QMAKE_CFLAGS_WARN_ON += -Wno-class-memaccess
QMAKE_CXXFLAGS_WARN_ON += -Wno-class-memaccess
QMAKE_CFLAGS += -Wno-class-memaccess
QMAKE_CXXFLAGS += -Wno-class-memaccess

Webots Qt framework libraries

I am creating a Webots project on OSX, where I am including the following:
#include <core/MainApplication.hpp>
I get error
In file included from
/Applications/Webots/resources/projects/default/libraries/qt_utils/core/MainApplication.hpp:17:
/Applications/Webots/webots.app/Contents/Frameworks/QtWidgets.framework/Headers/QApplication:1:10:
fatal error: 'qapplication.h' file not found
include "qapplication.h"
1 error generated.
All contnet of /Applications/Webots/webots.app/Contents/Frameworks/QtWidgets.framework/Headers/QApplication:
#include "qapplication.h"
QApplication file content is too short. Also it seems like I cannot find qapplication.h on the file system, is that normal?
Would it be more sensible to use local installation of Qt framework than the one that comes with Webots? How do I change the .pro file then to link to local installation of Qt rather than to /Applications/Webots/resources/projects/default/libraries/qt_utils
My make file:
CXX_SOURCES = entry_points.cpp
QT = core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
USE_C_API = true
QT_UTILS = /Applications/Webots/resources/projects/default/libraries/qt_utils
INCLUDE = -I"$(QT_UTILS)"
LIBRARIES = -L"$(QT_UTILS)" -lqt_utils
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
include /Applications/Webots/resources/Makefile.include
EDIT:
I have discovered that when I try to run make in the folder: /Applications/Webots/resources/projects/default/libraries/qt_utils
I get many errors (among many others), such as:
/Applications/Webots/webots.app/Contents/Frameworks/QtWidgets.framework/Headers/QWidget:1:10:
fatal error: 'qwidget.h' file not found
include "qwidget.h"
...
/Applications/Webots/webots.app/Contents/Frameworks/QtCore.framework/Headers/QObject:1:10:
fatal error: 'qobject.h' file not found
include "qobject.h"
...
/Applications/Webots/webots.app/Contents/Frameworks/QtWidgets.framework/Headers/QApplication:1:10:
fatal error: 'qapplication.h' file not found
include "qapplication.h"
In facts, these files are indeed missing from the Webots qt_utils
This is probably because of this line:
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
Indeed, QT_MAJOR_VERSION and greaterThan are not a part of the Webots Makefile system. If the Qt widgets module is not present, then the qapplication.h cannot be found (because it is precisely defined in the widgets module). As Webots is using Qt 5 since a while, I would recommend you to simply define the Qt modules like this:
QT = core gui widgets

Qwt and boost::signals

My project is using both Qt (included Qwt) and Boost::signals. As known, their macros are incompatible with each other. I compiled my project with CONFIG += no_keywords and renamed all Qt macros with upper-case registry i.e. signals = Q_SIGNALS. There are no more errors in project, but now I have errors in Qwt includes like this
/usr/include/qwtplot3d/qwt3d_extglwidget.h:101:1: error: ‘signals’ does not name a type
/usr/include/qwtplot3d/qwt3d_extglwidget.h:116:8: error: expected ‘:’ before ‘slots’
/usr/include/qwtplot3d/qwt3d_extglwidget.h:116:8: error: ‘slots’ does not name a type
It seems that Qwt is still conflicting with Boost::signals. What can I do here?
Qwt is compatible with boost signals - you are talking about a lib called QwtPlot3D !
When you want to use boost signals with QwtPlot3D you have to patch its implementation replacing the signal/slot/emit macros like you did it with your code.

Resources