英文:
No headers or source files in QT creator
问题
我在创建QT中的新头文件和源文件时遇到了问题。我只能将新文件添加到构建中,如下所示,对于“主”项目而言,它是灰色的。
我可以为构建专门创建它们,它们只会出现在文档区域中,没有头文件树分支。在我关闭qt后,我必须创建新的文件。我希望它们出现在树中并与主项目连接在一起。我已关闭“隐藏源文件和头文件”选项。
我显然尝试按照yt上显示的方式创建它们。我已经搜索了设置,但没有找到任何可用的选项。
英文:
I'm having a problem with creating new header and source files in QT. I can only add new files to the build, it's grayed for the "main" project as you can see below.
I can create them specifically for the build and they only appear once in the documents area. There is no header tree branch. After I close qt I have to create new ones. I want them to appear in the tree and be connected with the main project. I have "hide source and headers files" option off.
I've obviously tried creating them the way it was shown on the yt. I've searched through settings but didn't found anything I could use.
答案1
得分: 1
你需要在CMake中手动添加这些文件。
-
转到文件>新建文件,然后选择你需要的文件类型。通常会是源文件、头文件,或者两者都有(类文件)。
-
编辑CMakeLists.txt文件:
qt_add_executable(myapp
myapp.qrc
main.cpp
new_file.cpp
new_file.h
)
类似*.qml文件和像图片(.png .jpg)之类的资源都要添加到myapp.qrc文件中。
英文:
You will have to add the files manually in CMake.
-
Go to File>New File and select what type of file you want. Typically it will be a source, header, or both (class).
-
Edit the CMakeLists.txt file:
qt_add_executable(myapp
myapp.qrc
main.cpp
new_file.cpp
new_file.h
)
Resources like .qml files and things like images (*.png *.jpg) are added in the myapp.qrc file
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论