I'm trying to use Cmake to start a new Qt Project inside Visual Studio 2010. I want to recreate the standard setup, as if you were just creating a new Qt project inside MSVS using the Qt Add-in. Since I only have limited knowledge of Cmake and the internet is running out of ideas I need your help. The reason why I want to do this is because I have an existing Visual Studio project and I need to add a GUI.
So what I did was creating a new Qt project inside Visual Studio with just the default Qt-Window. What do I need to do in the CmakeLists.txt to achieve the same results? Or is it easier not to try to remake the standard project and just use the .ui file from the Designer? Do I need to do the whole qt5_wrap_cpp, qt4_wrap_ui and so on stuff in the Cmake?
I've searched for a solution for about two days now and I'm still there where I started.
Thanks for your help and guidance
I am also doing similar things, so I would like to share some views on it.
I created a project in QtCreator, with a project file .pro, .h, .cpp, .ui files. The qt project file .pro is for qmake. Then I transferred my project to MSVC. All I do is to transfer the .h .cpp .ui files to a new directory, and add a CMakeList.txt there.
If you have a existing Visual Studio project and you need to add a GUI, you can create a .uiin QtDesigner and add the .ui file to CMakeList.txt.
To create CMakeList.txt, you can go to the link in the comment above. Though I found the web quite hard to understand as a newbie. So basically, the CMakeList.txt would contain:
Follow the qt web for details when including the directories.
After that:
SET( PROJECT_SRCS
main.cpp)
SET( PROJECT_UIS //this is where you include your .ui files
Resources/UI/myui.ui)
SET( PROJECT_MOC_HDRS
mainWindow.h)
QT5_WRAP_UI( PROJECT_UIS_H //wrap ui files
${PROJECT_UIS}
)
QT5_WRAP_CPP( PROJECT_MOC_SRCS
${PROJECT_MOC_HDRS}
)
ADD_EXECUTABLE( MRT_1JUL
${PROJECT_SRCS}
${PROJECT_UIS_H}
${PROJECT_MOC_SRCS}
Related
I use CMake to create C++ projects. Then I would like to use Visual Studio as my IDE. But the issue I face is that I can't get files to be structured properly.
Here is the problem:
Let's assume I have the following file structure on the disk.
And here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
set(sourceDirectory src)
set(includeDirectory include)
set(targetName vulkan-tutorial)
set(targetVersion 1.0.0)
project(${targetName} VERSION ${targetVersion})
file(GLOB src
${sourceDirectory}/*.cpp
${sourceDirectory}/**/*.cpp
${sourceDirectory}/**/**/*.cpp
)
add_executable(${targetName} ${src})
target_include_directories(${targetName} PRIVATE ${includeDirectory})
Here is what this project looks like in Visual Studio with filters.
Or without using VS-filters.
I can create new files, but they're not going to land, where I want them to. The behavior I want to achieve is extremely simple: I want to see the root directory of my project and its "src" and "include" folders. I want to be able to right-click them and create new folders and files. Then I want Visual Studio to create them inside the selected folder. Like it would be in every normal file-explorer.
One solution I could imagine is to generate project files not inside a "build folder", but in the root directory of the project itself, which is obviously a terrible solution and leads to a pollution of the project structure.
Summarized - here is the result I want to end up with (now I can achieve it only by generating the project in the root). But all the build files should be located in the corresponding "build" folder in the root of the project.
I also would like to add that I tried to use different functions for CMake that kind of group my files together, but I just ended up with lots of filters that reflect my project structure on the disk. Of course, I still wasn't able to add new folders and files dynamically.
I appreciate any help. Thanks in advance.
Simply use the Open Folder option in visual studio.
This will open the directory and automatically configure the project using CMake. It will display the tree independently from the CMake configuration structure.
Microsoft has a page CMake projects in Visual Studio, that explains how to properly import CMake projects in visual studio
I want to add sound to my program so I need to add header file “QSound”.
To add the header file, I need to modify the .pro file.
The problem is, I use visual studio to develop projects, so I can't find the .pro file.
I am so confused.
Thanks for your help!
If you're using Qt VS Tools, use Create Basic .pro File from extensions menu. Note that .pro and .vcxproj files might not be in sync so if possible use Qt Creator to configure your project in the .pro file and then open the project in visual studio via Open Qt Project File
Note that if you are using MS Visual Studio and Qt, and you need to add a specific qt module to your project, you do not need to have a .pro file just for that. That would be the way to go when not using VS.
Instead, in Visual Studio select your project, select menu "Project / Properties", there you should have an entry "Qt Project Settings", and there a section "General", there a setting "Qt Modules" which probably already contains "core" and some entries.
Add your module to this line. Remember to do that for all your configurations and platforms.
I like to make Qt applications in Visual Studio. But sometimes, there is a need to continue development in Linux space, where Visual Studio is not available. Therefore, there's a need to write down project files manually.
Is it possible to generate .pro files and makefiles from configurated .sln file?
I don't use Microsoft Visual Studio so I never had to deal with .sln files.
But actually, to generate your Qt environment from the command line in linux, you don't need the .sln file.You just have to do as follows:
Create your project directory, let's call it MyQtProject
Copy inside your sources files (.h, .cpp)
Then cd MyQtProject and run qmake -project : It will read your directory and create your .pro file (adding your headers and sources files, ...).
You can edit the generated MyQtProject.pro file to add some specific instructions (for exampleQT += widgets)
Then you just have to run qmake MyQtProject.pro to generate the Makefile.
Finally run make to compile.
Of course, you can create a build directory inside MyQtProject and run qmake ../MyQtProject.pro and make from inside it in order to not pollute your project folder with the moc files and the cmake related files.
I hope it can help you and solve your problem.
I have a visual studio 2015 solution with multiple projects on it and I need to build it under Linux, so I used the QT plugin to create .pro file and export it to QtCreator. This worked fine for a single project but for a solution with multiple interdependent project I just couldn't find any option.
Also I tried creating a .pro file for each project to import each of them to QtCreator then create the inter-dependencies. but I couldn't find an option in QtCreator to add/import a sub-project, only creating a new one.
need your help, is there any one who've done that before?
Thanks
I would like to use Qt creator and Cmake together (please, don't ask me about my motivation, accept this as a given.)
I successfully set up Qt creator to use cmake "Cmake": see this, this and this documents regarding how I did that.
I successfully create hello world project, but I can't create files in project,
only add existing files to project tree and after that adding it to cmake list.
Standard operation of Qt creator "Add New..." doesn't work and I can't find why.
Is there anybody who uses Qt creator and "Cmake" together? Is the combination actually possible?
Note: I'm using Qt creator v2.4.1.
You can add files using glob expression in your CMakeLists.txt, like this:
file(GLOB SRC . *.cpp)
add_executable (your_exe_name ${SRC})
Cmake will pick your new cpp files next time you run it and QtCreator will show them in the project browser.
Update
This solution may be useful but as noted in comments - this is not a good practice. Every time somebody add new source file and commit changes, you need to rerun cmake to build all the sources. Usually I just touch one of the CMakeLists.txt files if my build is broken after I pool recent changes from repository. After that make will run cmake automatically and I didn't need to run it by hands. Despite of that I think that explicit source lists in CMakeLists.txt is a good thing, they called thing CMake Lists for a reason.
When you add new files in QtCreator using the "New File or Project..." dialog it only creates the files on disk, it doesn't automatically add the files to the CMakeLists.txt. You need to do this by hand by editing the CMakeLists.txt file.
The next time you build the project, CMake will be re-run, and QtCreator will pick up the new files and show them in the project browser.
I solve this problem that I added new files in standard way (CTRL+N), then added needed files in CMakeLists. After that, right click on project in project tree view and choose option Run CMake. After this, files showed in project list tree. Only build was not enough.
I tested here and happened the same behavior because those options you were asking were really disabled.
Use File -> "New File or Project..." or CTRL+N to add new files and after that add to CMakeLists.txt
I'm adding an updated answer for newer versions of QtCreator (4.x, I don't know precisely which release but at least from 4.7). In the Tools > Options... menu, choose the Build & Run section and then the CMake tab. You will see the Adding Files settings, and you can set it to Copy file paths :
This way, when you want to add a new file to your project, in the Project view, right click on the desired CMake Executable/Library's name and select Add New..., go through the Add dialog, and when you'll validate the dialog, QtCreator will open CMakeLists.txt in the Editor view. Finally, paste the content of the clipboard at the end of the corresponding source file list and save CMakeLists.txt. The CMake project will be parsed, and your new file will show up in the Project view.