Qt:Where to find the .pro file when developing with visual studio - c++

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.

Related

Precompiled header for moc_* in Visual Studio with Qt add-in

I try to make moc.exe to add a precompiled header include into generated moc_* files in Visual Studio with Qt plugin.
I tried to add a PRECOMPILED_HEADER=myheader.h (also with quotes) line into project's preprocessor definitions, that didn't work.
I also tried to add -DPRECOMPILED_HEADER=myheader.h as a parameter for moc.exe in the project *.vcxproj file.
Can anyone help?
Open Qt project settings (from context menu of vcxproj in VS) there you'll have moc options, in there you can use something like: -b stdafx.h
Note in VS2019 the integration changed and you have the Qt options integrated into the default options dialog, there you have Qt Meta-Object Compiler and an Force Include option, here you should not need the -b flag (but, you'll need to test that if this is the case). For more info you can check the documentation here.
Adding -fstdafx.h -f../%(Identity) to the moc.exe command line works for me.

Visual Studio 2010 Qt Add-in Cmake Project

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}

Multiple file compilation in visual C++ 2010

I have a very specific question in regards to visual C++ 2010 express. I have looked everywhere but can't find instructions on how to compile several source files. I have programmed on Unix at the command line and am trying to learn visual C++ 2010. I am using a header file that contains the function declarations and global variables. I don't know if this is the correct venue to ask this question but if anyone knows of some place where I can get the answer I would be grateful
Thanks,
Ral
If you have a project that you build from the command line with a makefile, then the Visual Studio development environment will not recognize your project. To open and build your project using Visual Studio, first create an empty project containing the appropriate build settings using the Makefile Project Wizard. You can then use this project to build your project from the Visual Studio development environment.
The project displays no files in Solution Explorer. The project specifies the build settings, which are reflected in the project's property page.
The output file that you specify in the project has no effect on the name that the build script generates; it declares only an intention.
Source: Creating a Makefile Project (VS2013)
On the menu: File->New->Project
On the dialog:
select Win32 Console Application,
enter Name ( like you did in the -o in unix) in the bottom,
and press OK
On the next dialog: Press next.
On the next dialog:
unmark Precompiled headers
mark Empty project
press Finish
Now find the Solution Explorer tree. You have Solution name and a project with the same name in it.
Right click on the project (not solution)
choose Add->Existing Item
and select your files, (you can copy them to the opened folder and then choose them)
press Add
Now you can try to compile.

visual studio 2010 doesn't update qrc files

I have a project on visual studio 2010 which uses qt, qrc files and qml. I've put my qml files inside qrc file, so when I rebuild the project my qrc files updates and I can reach my qml files.
The problem is when I update my qml files, visual studio (or qt visual studio plugin) can't detect the change and doesn't update the qrc files. Only thing I can do is either rebuild the project, or make some dummy changes to qrc file (add remove some white-space characters) so that qt plugin thinks that there may be some change in qrc file and it updates the qrc file.
This is time consuming, as I make several changes to my qml files it takes too much time to do this manually every time. Is there a practical way to do this?
Right-Click the file and select compile should do the trick.

Build a visual studio project on a subset of files in a directory

I would like to port my application from Linux to Windows. I'm trying to use visual studio to configure a project to build the Window application. The problem for me is that I only need a subset of files out my directory for Windows. But I would like to keep the integrity of the directory so that I don't need to checkout a subset of file to Windows. Does visual studio need the entire directory to be window files? For those who understand Window application development well, can you help me to understand:
Can I configure visual studio to build a project using a subset of the file from a directory?
If yes, how do I configure the project file? Any link to a tutorial would be really helpful.
Below are couple of quick suggestions using Visual Studio
Include/ Exclude :
If the number of file are minimum, then you could include or exclude files to a project manually.
You could add a directory to a project by copying the files to a folder under the .vcxproj(ur .<>proj) file.
Then select the project in the solution explorer and on the tool bar you would get an option Show All Files
Right click on the Folder or File and hit Include In Project. This will include the file/folder into your project.
You could Exclude any file that is already included in your project by, clicking the file and hit Exclude From Project.
Remove From Compilation Only:
Select the file in Solution Explorer and right click Properties
Under Configuration Properties -> General -> Excluded From Build set it to Yes/No