Connect to QtCreator .ui file directly to visual studio - visual-studio

Our team is using visual studio to write a whole project, and the user interface is made with Qt Designer to form a .ui file.
I wonder if there is a way to connect the .ui file directly into the c++ file in visual studio instead of in qtcreator. Also, I want to load the .ui file at runtime instead of qmake it into .cpp or .h file.
Thank you!

For UI file integration in Visual Studio, have a look at the Qt Visual Studio Add-In.
For loading UI files at runtime, have a look at the QUiLoader class.

Even the VisualStudio-integration will not integrate Qt's editor into VisualStudio. You can edit .ui's text content in VisualStudio's editor, but not the designer-editor. Thus, to layout and preview .ui, you have to open the .ui-files in seperate app (designer.exe or QtCreator)
Is is uncommon to load the .ui Files at runtime: Usually, you have a compile-step on the .ui File (which calls 'uic.exe'). - The so generated .cpp and .h files are compiled (at compiletime of course). You do not use the .ui at runtime. But...:
The generated .cpp/.h code contains Qt-Widgets. You can implement an interface for the widgets to be loaded at runtime. A good example for this is QtDesigner. The designer.exe loads widgets this way... at runtime!

Related

Is this a F++ project?

I am supposed to get a Visual Studio project to run again after several years. Originally it was written in Fortran and later a small GUI was build around it. Now my job is to change that GUI-part.
Since I am new to Visual Studio and Fortran, I need to know what kind of language the project (see below) is written in. I know there are Fortran files ( f90, fi, fd, for) but what language is .ico .rc.
It seems to be a F++-Project. But What is F++?
Is that similar to C++?
You are using Intel Visual Fortran in Microsoft Visual Studio. That little icon says Fo (for Fortran).
.ico is an icon file
.rc is a resource compiler file
These are used when creating Windows applications with a graphical user interface.
.fi and .fd are include files - the latter is created automatically from the .rc file when you build the project.

How can I manually add a resource to a Win32 resource file

Visual Studio Win32 projects have a resource file. One can add and configure controls using a GUI interface. However I have a need to enter about 80 check boxes which is very tedious using the GUI. I can open the resource file in a text editor, but if I try and add a new control, Visual Studio cannot understand it. I used to be able to do that in the old WATCOM C++ IDE/compiler.
Clearly VS is doing something else that just making the resource file.
Is there any way to create and add resources (lie controls) by manually editing the rc file?
Write the .rc file.
Use the resource compiler, rc.exe to compile the .rc file to a compiled resource, .res.
Pass the compiled resource to the linker.

Qt translator in VS 2010 - translation TS file names are put in the .pro file in Qt Creator, how is it done in Visual Studio?

I have code in C++ which needs to work with the Qt translation tools. In Qt Creator I would add
TARGET = translation
TRANSLATIONS = tran_ar.ts tran_en.ts tran_la.ts
into the .pro file. The development is being done in VS 2010 (the Gui is working fine so Qt is integrated). So where do I put this information in Visual Studio 2010?
Try the menu entry of the Qt plugin for VS:
Qt > Add new translation file
Select project and language, VS should then add a blank xxx.ts file to your project under "Localization Files" or some such. The context menu entry for this file contains links to "lupdate" and "lrelease", so I think you don't even need to bother with pro and pri files you wouldn't really use in VS anyway (I checked that the .qm files produced by lrelease appear to contain all translated entries of the .ts files).

using Qt designer in visual studio?

I'm using visual studio 2010, Qt add-in etc all ok, then create new project using Qt add-in... when doubleclicking *.ui (the actual form) file in VS it opens Qtdesigner, then I put some controls on, but that does not change my code at all :/
Qt form is changed it contains those controls but source files are the same as before even after building my project.
I'm I missing something?
I think Qtdesinger shoult put some code for objects which I created using Qtdesigner.
cos without that we must write all the code as if there were no Qtdesigner so Qtdesinger is useles in Visual studio, the same thing we could just do by hand-coding a form interface.
thanks alot.
EDIT:
OK
I've copied this from Qt site:
You are referencing objects from a .ui file...
The Visual Studio code model parser only parses C++ sources, meaning
that widgets or objects defined in .ui files will not be accessible.
To workaround the problem, the Qt Visual Studio Add-in automatically
generates C++ code from the .ui file by saving the file and running
uic on it. This step is done everytime the project is built. If the
code completion does not work, try to rebuild the project. It is
possible that you have to wait some time, before code completion fully
works after updating an .ui file. For more information, you can refer
to the Modifying Project Properties section. It still does not work...
You should refresh the code model, Intellisense. This is done by
opening the solution explorer, invoking the context menu of the
project and activating the item Update Intellisense.
now it looks that I'm having such problems but this does not help at all, update intelisece. I can't see such option in visual studio,
it looks my visual studio add-in isn't working.
it says "You should refresh the code model" Woot? can someone explain me how to do that please.
here are some output warnings when building my project:
Warning 1 warning : No resources in 'C:\Users\Admin\documents\visual
studio
2010\Projects\VisualStudio\test\test.qrc'. C:\Users\Admin\documents\visual
studio 2010\Projects\VisualStudio\test\RCC Warning 2 warning LNK4099:
PDB 'vc100.pdb' was not found with 'qtmaind.lib(qtmain_win.obj)' or at
'C:\Users\Admin\documents\visual studio
2010\Projects\VisualStudio\vc100.pdb'; linking object as if no debug
info C:\Users\Admin\documents\visual studio
2010\Projects\VisualStudio\test\qtmaind.lib(qtmain_win.obj)
I'm going to explain a little bit how things work and the relationships between the files, and hopefully this will solve your problem.
When you edit the ui file using the designer all changes are made to the ui file itself. Then when you build a couple of things will happen.
First... a custom build step will be run on the ui file. This build step runs "uic" as Macke said, and will generate a file called "ui_thenameofyouruifile.h". Where this file is located depends on your project settings, but if you look in your project you should see a folder called Generated Files in your project.
If you look in there you should see the newly generated file. This is the code that is "changed" when you make changes to your form. Now if this file is not updated, or does not exist at all, then somehow your project settings got messed up. In this case I would remove your .ui file from the project and re-add it. The add-in should do it's magic and add all the stuff you need. Build again and it should work. (I assume that is probably your problem)
The second thing that should happen when you build, is that the class that uses your ui file should recompile. Generally when you create a ui file, you also create an accompanying .h and .cpp file. This is where we do any of the fun logic that we might need in our window. The Qt designer will never ever change this class.
In the header file we refer to the ui file by doing this:
namespace Ui {
class thenameofyouruifile;
}
#include "ui_thenameofyouruifile.h"
and then we add a member variable
Ui::thenameofyouruifile UI;
There are a couple of ways to do this, but basically that's the idea. The add-in is supposed to configure your project so that the directory where the generate files go is included in the "additional include directories" in your project settings, but that is another place to check to make sure that your code is really linking with the correct generated file.
If Qt Add-In installed properly, it should generate the custom build step for Qt related files (.ui or moc file). I have not tried Qt Add-in with VS 2010, but with VS 2008 it's okay.
The work-around for your problem, you need to add manually the custom build step for each ui file you have in the project. To do this, the step is:
Right clicked the ui file, and click the properties (I'm using VS-2008 to do this step, and expect this may not be much different in VS 2010).
Under custom build step, add this in the command line: "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_$(InputName).h" "$(InputPath)"
And add this under output: ".\GeneratedFiles\ui_$(InputName).h"
And this under additional dependencies: $(QTDIR)\bin\uic.exe. Then click apply / ok.
If this is done, the ui file is compilable, (when you right click it, it can be compiled), so when the ui file content change, the new ui code (.h) file is regenerated.
Alternatively, to reset the VS project file (vcprojx) you can create Qt project in Qt creator, (or if you have already one), and then convert the Qt creator project (.pro) into vcproj using this command line:
qmake -spec win32-msvc2010 -tp vc
This will create the vcproj with the proper custom build step for you (in case you have many ui files, then you don't need to do the first approach).
If you've created a Qt widget using the new class wizard, stuff should work as expected.
I.e. your .ui files are compiled by Qt's uic to .cpp files, i.e. you need to build your project to get these changes into the ui-class.
So, the .ui files should be added to the project, and have some special build rules that invoke 'uic' on them. If that's not the case, try and re-add them to your project (that way, the Qt add-in should configure the build rules)
Normally, you have a class that inherits QWidget which then includes the compiled cpp-class, by one way or another, usually as a member variable (but inheritance is an option too).
Adding an .ui-file straight up should work too (if you're in a Qt project, which you are..), but obviously something is wrong.
Does the example projects work as expected?

How to perform "shell" icon embedding in Visual Studio 2010?

As far as I can tell, there have been (at least?) three types of icon embedding. There's the original style used by shell32.dll and friends, .NET's embedding, and the new type that WPF uses. I'm looking for how to perform the first one, as I want to have a few other icons available as resources for a jumplist, which can only accept that style. However, I can't figure out how to embed in this style, only the other two.
How do I do this? All the results I find on google, etc are for adding icons to ResX files or similar.
I never heard the term "icon embedding" before. If you are talking about the icon that's visible for a EXE or DLL in Explorer or a desktop shortcut: that's done the same way for any Windows program. Both WF and WPF give the assembly an unmanaged resource with the selected icon using the /win32res compile option. You can see it in Visual Studio with File + Open + File, select the EXE or DLL.
To create a .res file, first create a .rc file. You can create one with the C++ IDE. Right-click the solution, Add New Project, Visual C++, Win32, Win32 Console Application. Right-click the Resource Files folder, Add + Resource, select Icon, Import. select your file. Repeat as needed. After you build, you'll get a .res file in the project's Debug build directory.
Back to your C# project, Project + Properties, Application tab. Select the Resource File option and navigate to the .res file.
I'd highly recommend taking a look at this solution posted here (http://einaregilsson.com/add-multiple-icons-to-a-dotnet-application/). It integrates right into a ms build post build event and doesn't require an unmanaged project (to create an assembly from a .rc/.res file).
This removes a dependency on managing a second solution / assembly anytime you want update an icon and saves you from IL Merging the compiled c++ assembly.
I'd also recommend taking a look at WIX for your deployment. I've written a guide that accompanies this answer located here.

Resources