Qt plugin initialization failure upon starting Windows application - c++

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?

Related

QOpenGLWidget does not show on wayland: Protocol error

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)

‘class QApplication’ has no member named ‘setMainWidget’

I'm attempting to compile a "Hello World!" application using Qt but on compilation I'm getting the following error: ‘class QApplication’ has no member named ‘setMainWidget’ and I'm not sure why, my source file looks like:
/****************************************************************
**
** Qt tutorial 1
**
****************************************************************/
#include <qapplication.h>
#include <qpushbutton.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );
a.setMainWidget( &hello );
hello.show();
return a.exec();
}
and I created the Makefile with cmake using following CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0)
project(hello_world)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed
set(CMAKE_AUTOMOC ON)
# Create code from a list of Qt designer ui files
#set(CMAKE_AUTOUIC ON)
# Find the QtWidgets library
find_package(Qt5 COMPONENTS Widgets REQUIRED)
# Populate a CMake variable with the sources
set(hello_world_SRCS
main.cpp
)
# Tell CMake to create the helloworld executable
add_executable(hello_world WIN32 ${hello_world_SRCS})
# Use the Widgets module from Qt 5
target_link_libraries(hello_world Qt5::Widgets)
What am I doing wrong?

Getting reference issue in Qt while implementing OpenSceneGraph

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} )

cLion + Qt5 - exit code -1073741515 (0xC0000135)

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.

Preparing Qt for Windows

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();
}