I was trying to make some tests with the QOpenGLWidget class (Qt6), and I wrote the following main.cpp:
#include <QApplication>
#include <QOpenGLWidget>
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
QOpenGLWidget win(nullptr);
win.show();
return app.exec();
}
But, when executing on ubuntu/wayland, I get the following error:
The Wayland connection experienced a fatal error: Protocol error
If I set the following environment variable, works fine (a black window is shown):
QT_QPA_PLATFORM=xcb
Do I need to set some additional settings to have it working on wayland natively?
Or is there something wrong with my system configuration?
I am building with cmake:
cmake_minimum_required(VERSION 3.13)
project(FirstQtWindow)
find_package(OpenGL REQUIRED)
find_package(Qt6 COMPONENTS Gui OpenGLWidgets)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_executable(first-qt-window
main.cpp)
target_link_libraries(
first-qt-window
PUBLIC
OpenGL::GLU
Qt6::Core
Qt6::OpenGLWidgets)
Related
I could not start this simple startup code.
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
return app.exec();
}
The following popup appears:
The bin folder looks like this:
I build the project with the following Conan script:
...
options = {'qt6': 'ANY'}
default_options = {'qt:shared': True, 'qt6': None}
generators = 'cmake', 'cmake_paths', 'cmake_find_package', 'cmake_find_package_multi'
requires = 'qt/6.2.2'
...
My CMakeLists.txt is the following:
...
# Find Qt package.
find_package(Qt6 REQUIRED COMPONENTS Widgets Core)
# Find includes in the build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
# Turn on automatic invocation of the MOC, UIC & RCC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# Link the thirdparties.
target_link_libraries(${PROJECT_NAME} Qt6::Widgets Qt6::Core)
...
May I ask a suggestion what am I doing wrong?
Here is my main.cpp code:
#include <iostream>
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
using namespace std;
int main(int argc, char *argv[]) {
QApplication application(argc, argv);
QPushButton button("Hello, world!");
button.show();
return application.exec();
}
Running it in CLion IDE (latest version) gives me the following error:
Process finished with exit code -1073741515 (0xC0000135)
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
project(simple_interpreter)
set(CMAKE_CXX_STANDARD 14)
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif ()
set(ENV{PATH} "C:/Qt/5.14.2/mingw73_64/bin") # As suggested in https://stackoverflow.com/questions/44739411
set(Qt5_DIR "C:/Qt/5.14.2/mingw73_64/lib/cmake/Qt5")
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui)
add_executable(simple_interpreter main.cpp)
target_link_libraries(simple_interpreter Qt5::Core Qt5::Widgets Qt5::Gui)
From the CMake documentation for set(ENV ...):
This command affects only the current CMake process, not the process from which CMake was called, nor the system environment at large, nor the environment of subsequent build or test processes.
So, this does not set the PATH environment variable within your CLion environment. You should instead try appending the path C:/Qt/5.14.2/mingw73_64/bin to the Path variable in your System Environment Variables on your Windows machine. Then, be sure to restart CLion, so the Path variable update is applied.
I am getting error (**
**> CMakeFiles\untitled3.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x46):
undefined reference to `_imp___ZN9osgViewer6ViewerC1Ev'**)
while adding OpenSceneGraph in Qt. My profile is cmakelist.txt.
cmake_minimum_required(VERSION 2.8.12)
project(untitled3)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Core)
FIND_PATH(OPENSCENEGRAPH_INCLUDE_DIR osg/Referenced
PATHS
$ENV{OSG_ROOT}/include
$ENV{OSG_DIR}/include
/usr/include
/usr/local/include
)
FIND_PATH(OPENSCENEGRAPH_LIB_DIR libosg.so osg.lib
PATHS
$ENV{OSG_ROOT}/lib
$ENV{OSG_DIR}/lib
/usr/lib
/usr/local/lib
)
INCLUDE_DIRECTORIES(common ${OPENSCENEGRAPH_INCLUDE_DIR})
LINK_DIRECTORIES(${OPENSCENEGRAPH_LIB_DIR})
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} Qt5::Core)
My main.cpp file is
#include <QCoreApplication>
#include <osgViewer/Viewer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
osgViewer::Viewer viewer;
// viewer.setSceneData( osgDB::readNodeFile("cessna.osg") );
// return viewer.run();
return a.exec();
}
Any folks who can help. I invite them to come forward.
There is a problem with your cmake file. You need to make sure to:
Find the necessary OSG packages (osgViewer in your case).
Link your executable to the target OSG libraries.
Just like you did it for QtCore:
find_package(Qt5Core)
find_package(OpenSceneGraph REQUIRED COMPONENTS osgViewer)
# ...
target_link_libraries(${PROJECT_NAME} Qt5::Core ${OPENSCENEGRAPH_LIBRARIES} )
I'm trying to run simple test using QT5 and cLion but I run in to the exit code wall... Here is my envi :
cLion 2017.2
minGw 5.0 < according to cLion
cMake 3.8.2
Qt 5.9.0
CMakeList.txt
cmake_minimum_required(VERSION 3.8)
project(testWindotQt)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp )
add_executable(testWindotQt ${SOURCE_FILES})
if (WIN32)
# If you compile on windows replace path to your Qt folder
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.9\\mingw53_32")#\\lib\\cmake")
endif()
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
qt5_use_modules(testWindotQt Core Widgets Gui)
target_link_libraries(testWindotQt Qt5::Widgets Qt5::Core Qt5::Gui)
main.cpp
#include <iostream>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
int main(int argc, char *argv[])
{
std::cout << "Hello, World!" << std::endl;
QApplication a(argc, argv);
QLabel *label = new QLabel("HeyYou");
label->show();
return a.exec();
}
Execution >
Process finished with exit code -1073741515 (0xC0000135)
Can any1 help me out with this error please?
Regards
Dariusz
Have a look at this post: Setting up Qt for CLion
Basically, you have to add C:\QT\5.x\mingwxx_32\bin to your PATH environment variable.
I'm trying to setup Qt inside windows 8.1 using jetbrains Clion IDE but it does not show anything after compiling a simple test project. This is my main.cpp file:
#include <QApplication>
#include <QtWidgets/qpushbutton.h>
int main(int argc, char **argv)
{
QApplication *app = new QApplication(argc, argv);
QPushButton *X = new QPushButton("test");
X->show();
return app->exec();
}
This is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.2)
project(QtTest)
set(CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.5.0\\5.5\\mingw492_32\\")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(SOURCE_FILES main.cpp)
add_executable(QtTest WIN32 ${SOURCE_FILES})
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Multimedia REQUIRED)
qt5_use_modules(QtTest Core Widgets Gui Multimedia)
target_link_libraries(QtTest Qt5::Widgets Qt5::Gui Qt5::Core Qt5::Multimedia)
The output:
Process finished with exit code -1073741515 (0xC0000135)
Now I want some help to solve this problem.
The explicit memory management is unnecessary. You should also never need to use explicit Qt module prefixes - if you do, the build is not configured correctly. Finally, never use the qclass.h includes, use QClass.
Your code should read as follows. When your environment is correctly configured, it should build and run without any errors.
#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QPushButton button("test");
button.show();
return app.exec();
}