Process exit code 0xC0000135 while running Qt hello world - c++

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.

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)

Hooking up CLion with Qt

I want to be able to run my Qt applications from CLion. In order to do so, I'm using MinGW, CLion, and Qt 5.15.0. In Settings > Build, Execution, Deployment > CMake, I've set my CMake Options as the following:
-DCMAKE_PREFIX_PATH=/Qt/5.15.0/mingw81_64/lib/cmake
In Settings > Build, Execution, Deployment > Toolchains, I've set my Environment as the following:
C:\Qt\Tools\mingw810_64
The C and C++ compilers have been automatically detected so I'm not too worried about that. For the file main.cpp, I have the following:
#include <QApplication>
#include <QDebug>
int main() {
qDebug() << QT_VERSION_STR;
return 0;
}
For CMakeLists.txt, I have the following:
cmake_minimum_required(VERSION 3.3)
project(Practice)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
find_package(Qt5Widgets REQUIRED)
add_executable(Practice ${SOURCE_FILES})
target_link_libraries(Practice Qt5::Widgets)
Building this test project gives me no warnings or errors but running it does. Why is this? Here's the error code I get when it does run.
C:\Users\IvanJaramillo\CLionProjects\Practice\cmake-build-debug\Practice.exe
Process finished with exit code -1073741511 (0xC0000139)
Changing compilers from MinGW to Cygwin and changing the versions of it hasn't done the job.

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.

Index Qt5 in Eclipse IDE project using Cmake

Background
I'm currently using Eclipse Neon.3 and have installed the "C/C++ CMake Build Support - Experimental" package (I'm not using CMake's Eclipse generator). I have a simple program that uses Qt 5.8 which builds successfully, however, Eclipse seems unable to index Qt symbols(e.g. QCoreApplication, QDebug, etc...).
The symptoms of this are:
No code completion suggestions
#include <QtCore> and other include statements are shown as unresolved
Qt symbols such as QCoreApplication, QDebug(), and QCoreApplication.exec() are shown as not resolved.
Code
CMakeLists.txt file
cmake_minimum_required(VERSION 3.5)
project(test-program)
set(CMAKE_CXX_STANDARD 11)
# Put the CMake files for Qt5 in the Prefix path.
set(Qt5_DIR /opt/Qt/5.8/gcc_64/lib/cmake/Qt5/)
#Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
#Find the Qt5Core Library
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
set(SOURCE_FILES
src/main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
main.cpp (shown with eclipse annotations)
#include <QtCore> //Unresolved inclusion: <QtCore>
#include <QDebug> //Unresolved inclusion: <QDebug>
int main(int argc, char** argv){
QCoreApplication application(argc, argv);
//Type 'QCoreApplication' could not be resolved
qDebug() << "Test";
//Function 'qDebug' could not be resolved
application.exec();
//Method 'exec' could not be resolved
return 0;
}
Question
So my question is this: How can I get Eclipse to recognize Eclipse to recognize Qt symbols? Or is that just not possible at this time?
Did you enable the "CDT GCC Build Output Parser"? This is an Eclipse feature to parse the output of the build and guesses the include paths automatically. You can find it unter Project Properties->C/C++ General->Preprocessor Include Paths, Macros etc. and then under the tab Providers.
In order for this feature to work properly, a detailed build report must be generated. You can achieve this by either changing the build command under Preferences->C/C++ Build to make VERBOSE=1 or by specifying set(CMAKE_VERBOSE_MAKEFILE On) inside your CMakeLists.txt.
See also Eclipse Help - Scanner Discovery Preferences

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