用VSCODE& C++
我是C ++以及VSCODE的新手,因此这个问题可能会有一个非常简单的答案,我只是在忽略。在喜欢其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 Code 2017
- CMake(扩展)
- CMAKE工具(扩展)
- QT Tools(扩展)QT Tools(扩展)
- GCC 8.1。 0x86_64-W64-MINGW32编译器
- QT 6.3.0
令我感到困惑的是,该程序似乎没有错误 - 该程序在编译时找到QT并没有抛出任何错误。但是,每当我从VS代码终端启动它时,什么也不会发生。没有打印任何声明,也没有启动任何窗口。 如果它有所帮助,这是我尝试启动它的输出:
[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>
我将非常感谢可以将我指向解决此问题的任何人。鉴于没有错误消息,所以我对从哪里开始失去了我的迷路。如果你们中的任何人都需要更多信息,我会很乐意为其提供。 :)
I am new to C++ as well as VSCode, so this issue might have a really simple answer I'm just overlooking. I'm trying to build an application using the Qt library after having loved its PyQt variant, but I cannot get the simplest possible app to launch from the VSCode terminal.
Here's the program I try to build and run:
// 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();
}
Here's the CMakeLists.txt file that builds the app:
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)
These are the components I'm using:
- VS Code 2017
- CMake (extension)
- CMake Tools (extension)
- Qt tools (extension)
- GCC 8.1.0x86_64-w64-mingw32 compiler
- Qt 6.3.0
What confuses me is that the program builds seemingly without error - the program finds Qt and throws no error when compiling. But whenever I launch it from the VS Code terminal, nothing happens. No statement is printed nor is any window launched.
In case it helps, here's the output when I try to launch it:
[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
Terminal results:
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>
I would be immensely grateful to anyone who can point me in a direction to solve this. Given that there are no error messages, I'm lost as to where to start. If any of you guys need any more information, I'll be happy to supply it. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论