使用 VSCode 和 C++ 启动 QApplication 类时遇到问题

问题描述 投票:0回答:1

我是 C++ 和 VSCode 的新手,所以这个问题可能有一个非常简单的答案,我只是忽略了。在喜欢 Qt 的 PyQt 变体之后,我尝试使用 Qt 库构建一个应用程序,但我无法从 VSCode 终端启动最简单的应用程序。 这是我尝试构建和运行的程序:

// main.cpp - I copied and pasted the Qt documentation example after I had Qt import issues
// (which I have since resolved)
#include <iostream>
#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
    std::cout << "So far";
    QApplication qga (argc, argv);
    QPushButton btn ("ayo");
    btn.show();
    return qga.exec();
}

这是构建应用程序的 CMakeLists.txt 文件:

cmake_minimum_required(VERSION 3.16)
project(trial VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


set(CMAKE_PREFIX_PATH "C:/Qt/6.3.0/mingw_64/")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt6 REQUIRED COMPONENTS Widgets Gui Core)

qt_standard_project_setup()


add_executable(trial main.cpp)

target_link_libraries(trial PRIVATE Qt6::Widgets Qt6::Gui Qt6::Core)
include(CPack)

这些是我正在使用的组件:

  • VS 代码 2017
  • CMake(扩展)
  • CMake 工具(扩展)
  • Qt 工具(扩展)
  • GCC 8.1.0x86_64-w64-mingw32 编译器
  • Qt 6.3.0

令我困惑的是,程序的构建似乎没有错误 - 程序找到 Qt 并且在编译时没有抛出错误。但每当我从 VS Code 终端启动它时,什么也没有发生。没有打印任何声明,也没有启动任何窗口。 如果它有帮助,这是我尝试启动它时的输出:

[variant] Loaded new set of variants
[kit] Successfully loaded 5 kits from C:\Users\astro\AppData\Local\CMakeTools\cmake-tools-kits.json
[proc] Executing command: C:\MinGW64\bin\gcc.exe -v
[main] Configuring folder: qttrial 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\MinGW64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\MinGW64\bin\g++.exe -Sc:/Users/astro/Desktop/Git/qttrial -Bc:/Users/astro/Desktop/Git/qttrial/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 8.1.0
[cmake] -- The CXX compiler identification is GNU 8.1.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/MinGW64/bin/gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/MinGW64/bin/g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Looking for pthread.h
[cmake] -- Looking for pthread.h - found
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
[cmake] -- Check if compiler accepts -pthread
[cmake] -- Check if compiler accepts -pthread - yes
[cmake] -- Found Threads: TRUE  
[cmake] -- Performing Test HAVE_STDATOMIC
[cmake] -- Performing Test HAVE_STDATOMIC - Success
[cmake] -- Found WrapAtomic: TRUE  
[cmake] -- Found WrapVulkanHeaders: C:/VulkanSDK/1.3.211.0/Include  
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/Users/astro/Desktop/Git/qttrial/build
[main] Building folder: qttrial trial
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/astro/Desktop/Git/qttrial/build --config Debug --target trial -j 14 --
[build] [ 25%] Automatic MOC and UIC for target trial
[build] [ 25%] Built target trial_autogen
[build] [ 50%] Building CXX object CMakeFiles/trial.dir/trial_autogen/mocs_compilation.cpp.obj
[build] [ 75%] Building CXX object CMakeFiles/trial.dir/main.cpp.obj
[build] [100%] Linking CXX executable trial.exe
[build] [100%] Built target trial
[build] Build finished with exit code 0

终端结果:

PS C:\Users\astro\Desktop\Git\qttrial\build> ."C:/Users/astro/Desktop/Git/qttrial/build/trial.exe"
PS C:\Users\astro\Desktop\Git\qttrial\build>

我将非常感谢任何能够为我指出解决这个问题的方向的人。鉴于没有错误消息,我不知道从哪里开始。如果你们中有人需要更多信息,我很乐意提供。 :)

c++ visual-studio-code cmake qt6
1个回答
0
投票

您好,您还在吗,我在这里也遇到了同样的问题。你能告诉我更多关于你是如何解决的吗?

© www.soinside.com 2019 - 2024. All rights reserved.