How add new form in QT application - c++

I use Visual studio 2012, and add plugin for QT. How to add new form to main window? When i try to add new item, compiler don't generates code, when i click to .h file it says "the document cannot be opened. it has been renamed deleted or moved".
Thanks.

If you have the Visual Studio plugin installed and you add a new Qt form to the project, two new files are added to your project, a xxx.ui file under the Form Files folder and a ui_xxx.h under the Generated Files folder.
You will be allowed to edit the xxx.ui file by double-clicking on it and Qt Designer will open up.
The ui_xxx.h file will not initially be editable (not that you'd want to edit it anyway) because only a reference to it gets added in the project file, no physical file is created on the disk. The header file is only created when you execute your next build.
EDIT:
If you don't want to do a full build, you could also just right-click on your new xxx.ui file in the Solution Explorer and select Compile from the context menu. That will run uic to generate your header code.

Related

visual studio c++ does it build only files shown in the tab?

I'm new to C++ and was following the instruction steps here
The situation was I have math.cpp file where contains two functions.
One of those function was already in the other cpp file in the same project so I have removed it.
The build worked however, when I tried to recreate the removed cpp with the same name, it said this already exsits. In the file explorer, the file was there not deleted completely.
Now I'm confused how this visual studio building works.
Does it only builds the cpp files which is shown in the tab even though some files not included may exist in the same folder?
I was wondering wouldn't this cause a problem in the future when you are programming and some of the files not shown in the tab?
Removing the file does not delete it from the directory, it removes it from the project. So it's still there in the directory. When you right-click on the file and attempt to remove it, it should give you the option to delete the file or remove it. Now that you have removed it right click on the source files folder and add then existing item. Now navigate to where the cpp file is and add it back.

Visual Studio - why does stdafx.h gets embedded

I am Unix guy but for a project I need to code in VS 2015. Basically I need to write some GMOCK test cases for some C++ classes.
I first tried to start with a sample project so I selected File->New->Project->Win32->Win32 Console Application. The project did got created with a default name ConsoleApplication2.cpp having embedded statement -
#include "stdafx.h"
I found that if I delete this line the code fails to compile - Usually in Unix I create .h and .cpp files and then create its make file - my aim was to start a project - create some .h files first and then create its .cpp / GMOCK test cases and build then build all
Please let me know if there is an option in VS for same or the way to do so?
for the use of stdafx.h please see the link Here
If you want to add a header file and then the respective cpp file the you just need to go to the project in solution explorer at right side of your IDE. Right click and go for add. There you will get the option for header file and class both.
You can add from there and start writing your code for the test cases.
The steps to create an empty project without precompiled headers or additional default source files are:
After you select "Win32 Console Application" click "OK".
On the following dialog click "Next" to go to the Application Settings page.
Select the "Empty project" option and then click "Finish".
The "Empty project" option says:
This option creates a .vcxproj file based on the project name you specified but adds no files to it. Use this when you intend to supply all your own source files.

Copying source files into a Visual Studio project

I've created a new Visual Studio C++ project and I'd like to import copies of a number of C and header files into the project. That is, the files are currently in a folder on my desktop and I'd like to import them such that copies are placed in the newly created project folder.
How would I do this? I've tried using File | New | Project from Existing Code but that just keeps the files in their existing location. I've even tried a simple Ctrl-C and Ctrl-V and again that imported the files but they stayed in the same place on disk.
Copy the files to the new location in Windows Explorer, then start Visual Studio and add them as existing items to the project.
I think the better solution would be to create a new (empty) project and add your h and cpp files per "Add -> Existing item" in the context menu of "Headers" and "Sources"

How to create a folder in Visual Studio C++ 2012

I have started my first bigger project with Visual Studio 2012 in C++. I will structure my Source-files in folders, but I can not find where I can create real folders, like in the windows explorer. So here is my question.
How can I create real folders in my project?
The IDE has a command for that, "New Folder". It is even present in the Project + Add context menu, something you can see when you look at the context menu with Tools + Customize. It is however hidden in the C++ IDE. Intentionally.
Its important to understand why it is hidden. It keeps you out of trouble, the kind of trouble you'll get into when you create folders with Explorer.
At issue is the way C++ files get built. They produce an .obj file when the compiler is done with them. That obj file is stored in a directory whose name is a project setting. You see it with Project + Properties, General, Intermediate Directory setting. For an individual .cpp file, it is C/C++, Output Files, Object File Name. The default for that one is $(IntDir) a macro that tells the compiler to use the Intermediate Directory setting. With the default settings, all .obj files for the Debug build end up in the Debug subdirectory. Release subdirectory for the Release build. Regardless where the .cpp was stored.
Maybe you see the bear trap by now. If you create a subdirectory with .cpp files then you'll get in trouble when that subdirectory has a .cpp file whose name is identical to another .cpp file in another subdirectory. They produce an .obj file with the same name. One overwrites the other, which ever one was compiled last. That produces very mystifying linker errors. You'll get duplicate symbol errors because the last built .obj file is linked twice and missing symbol errors for the overwritten .obj file.
So go ahead and create a subdirectory but beware this problem. You have to change the Object File Name setting for the .cpp file if such a collision happens.
This is mildly annoying, however, here is what can be done:
Create the new folder in Visual Studio. This does not create a new folder in the file system. Add a new item to the folder. Choose the proper directory for the item.
For example, if your project is at %Documents%\Project, and your new folder name is Folder, then you add a new item to that folder at %Documents%\Project\Folder.
Visual Studio 2012 will put the item in the folder where you want it. If you add a new item, it will default to the same folder. That is where the annoying part comes in. If you create 3 folders for all your project items and try to add a new item to each folder, Visual Studio will try to put all 3 items in the same place in the file system (the last folder you added a new item to), while putting items into the correct Visual Studio folder.
It is possible there is a setting for this in Visual Studio. I haven't found it. I also haven't looked that hard.

Qt ui file does not compile in to C++ header

I've created a Qt Application project in Visual Studio 2010. It contains the following files
Form Files
mainwindow.ui
Header Files
mainwindow.h
Source Files
mainwindow.cpp
It also uses a generated codefile called ui_mainwindow.h. From what I've been able to discern, this file should be regenerated in response to changes made to the .ui file. However if I open the ui file in Designer and make a change, no change appears in the application.
I have to go to Form -> View Code -> Save As in Qt Designer and save the ui_mainwindow.h file manually.
.ui file should have custom build tool defined to use uic on it and produce appropriate ui_*.h file.
Custom build tool command line may look like this:
uic.exe "$(InputPath)" -o "ui_$(InputName).h"
Also, in order to properly detect dependencies and to Clean command remove generated file, add ui_$(InputName).h to Custom Build Tool Outputs.
Don't forget to make the changes for all Configurations and Platforms.
Although, the right way to do this would be to create appropriate .pro file and then generate Visual Studio project with qmake -tp vc project.pro. All compiler and linker settings should be adjusted in .pro file, not in Visual Studio project that should be regenerated after each change of .pro file.
i mean no offense but have you saved the .ui file before running the project?
when i need to edit the ui files, i change them with the designer and when i want to run it, it will recompile/moc/whatever the changed ui file and their .h/.cpp file as well.