iostream library doesn't work using Qt's cmake

97 Views Asked by At

I have recently set up Qt6 with CLion in order to start making small GUI's. However when i first tried to add some console outputs using the "cout". my code exits with code (0xC0000005)...

Here is my CMakeLists.txt

cmake_minimum_required(VERSION 3.26)
project(Simple_GUI)

set(CMAKE_CXX_STANDARD 17)

#=============== INCLUSION OF Qt ================#
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_PREFIX_PATH "C:\\Qt\\6.5.2\\mingw_64\\lib\\cmake")

find_package(Qt6Core REQUIRED) #find needed packages
find_package(Qt6Widgets REQUIRED)

#=========== ADDING EXECUTABLE AND LINKING LIBRARIES ============#
add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} Qt6::Widgets)

and here is main.cpp:

#include <QtCore/QCoreApplication>
#include <QDebug>
#include <string>
#include <iostream>

int main(int argc, char** argv) {

    std::string h("Hello World");
    qDebug() << h;
    std::cout << h << std::endl;

    //==========Minimal source code of a Qt application=====:
    QCoreApplication app(argc, argv); 

    return QCoreApplication::exec();
}

the moment i take out the std::cout << ... line, everything works fine again. qDebug() works as well.

edit: here's the gdb output:

enter image description here

0

There are 0 best solutions below