Using the Qt constructor in visual studio?

I use visual studio 2010, Qt add-in, etc., everything is fine, and then create a new project using Qt add-in ... when I double-click the * .ui (actual form) file in VS it opens Qtdesigner, then I add some controls, but that doesn't change my code at all: /

The Qt form has been modified, it contains these controls, but the source files are the same as before the creation of my project.

Am I missing something? I think Qtdesinger shoult put some code for the objects that I created using Qtdesigner.

cos, without this we have to write all the code, as if there was no Qtdesigner, so Qtdesinger is useles in Visual studio, the same thing that we could only do by manually coding the form interface. Many thanks.

EDIT:

OK I copied this from the Qt website:

You are referencing objects from a .ui file ...

The Visual Studio code model parser only analyzes C ++ sources, which means that widgets or objects defined in .ui files will not be available. To work around this problem, the Qt Visual Studio add-in automatically generates C ++ code from the .ui file, saving the file and running uic on it. This step is performed every time a project is built. If code completion does not work, try rebuilding the project. it is possible that you need to wait a while until the code completes completely after updating the .ui file. For more information, you can refer to the section "Changing project properties". It still doesn't work ...

You must update the Intellisense code model. This is done by opening the solution explorer, calling the project context menu and activating the Update Intellisense element.

Now it seems like I have such problems, but it doesnโ€™t help at all, update intelisece. I do not see such a possibility in the visual studio, it seems my visual studio add-in does not work.

he says: โ€œYou have to update the code modelโ€ Woot? can someone explain me how to do this, please.

Here are some output warnings when creating my project:

Warning 1 warning: there are 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 warning: PDB 'vc100.pdb' was not found with 'qtmaind.lib (qtmain_win.obj)' or in 'C: \ Users \ Admin \ documents \ visual studio 2010 \ Projects \ VisualStudio \ vc100. pdb '; binding the object as if debugging information C: \ Users \ Admin \ documents \ visual studio 2010 \ Projects \ VisualStudio \ test \ qtmaind.lib (qtmain_win.obj)

+6
source share
3 answers

Iโ€™ll explain a little how everything works, and the relationship between files, and I hope this solves your problem.

When you edit the ui file using the constructor, 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 in the ui file. This build step starts uic, as Macke said, and creates a file called ui_thenameofyouruifile.h. If this file is located, it depends on the settings of your project, but if you look in your project, you will see the "Generated files" folder in your project.

enter image description here

If you look there, you will see a new file. This is the code that โ€œchangesโ€ 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 are confused. In this case, I will delete your .ui file from the project and add it again. The add-in should do this magic and add everything you need. Build again and it should work. (I guess this is probably your problem)

The second thing that should happen when you create it is that the class that your ui file uses must recompile. Usually, when you create a ui file, you also create an accompanying .h and .cpp file. Here we make any of the fun logic that we may need in our window. The Qt designer will never change this class.

In the header file, we refer to the ui file:

namespace Ui { class thenameofyouruifile; } #include "ui_thenameofyouruifile.h" 

and then add a member variable

Ui :: thenameofyouruifile UI;

There are several ways to do this, but basically this idea. The add-in is supposed to configure your project so that the directory in which the files were generated is included in the "extra inclusion directories" in your project settings, but this is another place to check if your code is really associated with the correct generated file.

+6
source

If the Qt add-in is installed correctly, it should create a custom build step for the associated Qt files (.ui or moc file). I have not tried the Qt add-in with VS 2010, but with VS 2008 everything is fine.

To work around your problem, you need to manually add a custom build step for each ui file that you have in the project. To do this, step:

  • Right-click the ui file and select properties (I am using VS-2008 for this step and expect this to not be much different in VS 2010).

  • In the custom assembly section, add this to the command line: "$ (QTDIR) \ bin \ uic.exe" -o ". \ GeneratedFiles \ ui _ $ (InputName) .h" "$ (InputPath)"

  • And add this under the output: ". \ GeneratedFiles \ ui _ $ (InputName) .h"

  • And this is under additional dependencies: $ (QTDIR) \ bin \ uic.exe. Then click apply / ok.

If this is done, the ui file will be compiled (when you right-click it, it can be compiled), so if you change the contents of the ui file, the new ui-code (.h) file will be restored.

Alternatively, reset the VS project file (vcprojx), you can create a Qt project in the Qt creator (or if you already have one), and then convert the Qt design project (.pro) to vcproj using this command line:

 qmake -spec win32-msvc2010 -tp vc 

This will create vcproj with the appropriate custom build step for you (if you have many ui files, you do not need to do the first approach).

+2
source

If you created a Qt widget using the new class wizard, everything should work as expected.

those. your .ui files are compiled by Qt uic into .cpp files, i.e. you need to build your project to get these changes in the u-class.

So, .ui files must be added to the project and have some special build rules that call uic on them. If this is not the case, try and re-add them to your project (thus, the Qt add-in should configure the build rules)

Usually you have a class that inherits a QWidget, which then includes a compiled cpp class, one way or another, usually as a member variable (but inheritance is also an option).

Adding a .ui file should work too (if you are in the Qt project that you have), but obviously something is wrong.

Does the sample project work as expected?

0
source

Source: https://habr.com/ru/post/902594/


All Articles