Qt Designer Go To Slot Missing Visual Studio

In Qt Designer's signals and slots editing mode, you can connect objects in a form together using Qt's signals and slots mechanism. Both widgets and layouts can be connected via an intuitive connection interface, using the menu of compatible signals and slots provided by Qt Designer. When a form is saved, all connections are preserved so that they will be ready for use when your project is built.

For more information on Qt's signals and sltos mechanism, refer to the Signals and Slots document.

Connecting Objects

Aug 16, 2014  Qt has official support for visual studio, as I said, comercial only. Unfortunetely I think VS is the only IDE that is supported from Qt side, but I'm not 100% sure. There may be ways to make things work manulay with various IDE's but nowdays it's just more. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! Asking for help, clarification,.

To begin connecting objects, enter the signals and slots editing mode by opening the Edit menu and selecting Edit Signals/Slots, or by pressing the F4 key.

All widgets and layouts on the form can be connected together. However, spacers just provide spacing hints to layouts, so they cannot be connected to other objects.

Highlighted Objects

When the cursor is over an object that can be used in a connection, the object will be highlighted.

To make a connectionn, press the left mouse button and drag the cursor towards the object you want to connect it to. As you do this, a line will extend from the source object to the cursor. If the cursor is over another object on the form, the line will end with an arrow head that points to the destination object. This indicates that a connection will be made between the two objects when you release the mouse button.

You can abandon the connection at any point while you are dragging the connection path by pressing Esc.

Making a Connection

The connection path will change its shape as the cursor moves around the form. As it passes over objects, they are highlighted, indicating that they can be used in a signal and slot connection. Release the mouse button to make the connection.

The Configure Connection dialog (below) is displayed, showing signals from the source object and slots from the destination object that you can use.

To complete the connection, select a signal from the source object and a slot from the destination object, then click OK. Click Cancel if you wish to abandon the connection.

Note: If the Show all signals and slots checkbox is selected, all available signals from the source object will be shown. Otherwise, the signals and slots inherited from QWidget will be hidden.

You can make as many connections as you like between objects on the form; it is possible to connect signals from objects to slots in the form itself. As a result, the signal and slot connections in many dialogs can be completely configured from within Qt Designer.

Connecting to a Form

To connect an object to the form itself, simply position the cursor over the form and release the mouse button. The end point of the connection changes to the electrical 'ground' symbol.

Slot

Editing and Deleting Connections

By default, connection paths are created with two labels that show the signal and slot involved in the connection. These labels are usually oriented along the line of the connection. You can move them around inside their host widgets by dragging the red square at each end of the connection path.

The Signal/Slot Editor

The signal and slot used in a connection can be changed after it has been set up. When a connection is configured, it becomes visible in Qt Designer's signal and slot editor where it can be further edited. You can also edit signal/slot connections by double-clicking on the connection path or one of its labels to display the Connection Dialog.

Deleting Connections

The whole connection can be selected by clicking on any of its path segments. Once selected, a connection can be deleted with the Delete key, ensuring that it will not be set up in the UI file.

© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

In this tutorial, we will create an address book application step-by-step using the Qt Visual Studio Add-in. We will also outline how to create a basic project using the Qt5 project wizard and design a form with Qt Designer. In addition, we will also show you how to convert a Visual Studio project file into a qmake compatible .pro file.

Prerequisite

To create a Qt VS Add-in project, at least one Qt version must be added. Adding a Qt version enables you to choose the modules required for the project. For more details, see Managing Projects.

Creating a Skeleton Qt Application

The first step is to create a trivial project. To do so, select the New Project dialog in Visual Studio and click the Qt5 Projects folder. Then select the Qt Application item and type 'AddressBook' in the Name field.

When you click OK, a project wizard will appear. This wizard has a page listing Qt modules you can link your project against, followed by a page that enables you to specify the name of a skeleton class that will be generated by the wizard as a starting point. For this Address Book example, we will use the default values.

Now, we have a small working Qt application. Press F5 to try it out. The result is an empty window.

Designing the Main Dialog

Next, we will design the application's main dialog using Qt Designer. See the Qt Designer Manual for more information.

We begin by adding the widgets and setting their properties. These widgets are then put into layouts. The result is shown below.

Adding the Widgets

We launch Qt Designer by double-clicking on the Form Filesaddressbook.ui file in Visual Studio's Solution Explorer.

First, we add the QListWidget. Expand the Item-Based Widgets group in the Widget Box, then click on the List Widget subitem and drag it to the top-left corner of the form. The Property Editor will now display the properties for the QListWidget object. Using this editor, set the ObjectName property to 'addressList'.

Next, we insert the Add and Delete buttons. Expand the Buttons group in the Widget Box and drag two Push Buttons to the top-right corner of the form. Rename the buttons to 'addButton' and 'deleteButton', and their Text property to 'Add' and 'Delete'.

Finally, we add two QLabel objects to display the selected item in the list by dragging the Label item from the Display Widgets group onto the form, once for each label.

Rename the first label to 'nameLabel' and change its Text property to '<No item selected>'; rename the second label to 'emailLabel' and leave its Text property empty.

Try to position the widgets as they appear in the screenshot above.

Adding the Layouts

In order to properly position the widgets and ensure that they resize accordingly when the form is resized, we need to add layouts to the form.

We require a vertical layout for the buttons as well as a spacer to push the buttons to the top of the layout. To add a spacer, drag the Vertical Spacer item from the Spacers group onto the form. Then, select the buttons and the spacer (click on each widget while holding Shift) and click Form|Layout Vertically.

The window also needs a layout to manage the positioning of other widgets as well as the button layout. So we add another layout by selecting the list widgets, the two labels and the button layout, and then clicking Form|Layout in a Grid.

Note: Make sure that the labels are almost as wide as the form; otherwise the grid layout will make them only as wide as the address list.

To preview your form without compiling it, click Form|Preview.... To build and run the application, leave Qt Designer after saving the form and press F5 in Visual Studio.

Adding an 'Add Address' Dialog

Now that the main dialog is done, we move on to add functionality to our address book application. We would like to have an application that pops up a dialog when the user clicks the Add button. Hence, we require an 'Add Address' dialog.

Designing the Dialog

We start by designing the dialog. This time, there is no ready-made .ui file available in the project. So, we select Project|Add Class...|Qt5 Classes|Qt5GuiClass. This will invoke a wizard requesting for a class name. Enter 'AddDialog' as the name and 'QDialog' as the base class. Then, check the 'Multiple Inheritance' checkbox and click on the Finish button.

You will now have an adddialog.ui file in the project's Form Files folder.

To set the properties of the dialog, double-click on adddialog.ui to open the form in Qt Designer. Then, click on the form and set its WindowTitle property to 'Add Address'. Next, create the following widgets and set their ObjectName and Text properties according to values listed in the table below.

WidgetObjectNameText
QLabel'nameText''Name:'
QLabel'emailText''Email:'
QLineEdit'nameEdit''
QLineEdit'emailEdit''
QPushButton'okButton''OK'

Now you can lay out your widgets. Use a grid layout for the labels and line edits.

Connecting to the Dialog's OK Button

We want the OK button to invoke the QDialog::accept() slot, and we do this by clicking on the Edit Signals/Slots toolbar button. You will then enter Qt Designer's Signal and Slots Editing Mode.

Click on the OK button and drag the mouse cursor to an empty area of the form and release the mouse button. The Configure Connection dialog will pop up, allowing you to establish a signal-slot connection between the OK button and the form. Connect the button's QPushButton::clicked() signal to the form's QDialog::accept() slot.

Displaying the 'Add Address' Dialog from the Application

Once we have completed designing the dialog, we have to invoke it when the user clicks the main dialog's Add button. To achieve this behavior, we add a slot to the AddressBook class and invoke the AddDialog from this slot.

Forms created using Qt Designer call QMetaObject::connectSlotsByName() to establish connections between signals emitted by the form's child widgets and slots that follow the naming convention on_<sender>_<signal>(). To react on clicking the add button you must implement a slot called on_addButton_clicked(). Type in the following lines of code in the slot's body:

If we want to connect to another signal, instead of QPushButton::clicked(), we have to add another signal to the AddressBook class. This requires editing both the header file (addressbook.h) and the implementation file (addressbook.cpp).

Next, we include adddialog.h to addressbook.cpp:

Build and run the program now. If you click on the Add button, the Add Address dialog will pop up. If you click on OK, the dialog will disappear.

Adding Items to the List Widget

When the user clicks OK, we would like to add an item to the QListWidget. To do so, modify the code in the on_addButton_clicked() slot to the following:

Qt Designer Go To Slot Missing Visual Studio

Download Qt For Visual Studio

We execute the dialog. If the dialog is accepted, for example, OK is clicked, we extract the Name and Email fields and create a QListWidgetItem with the given information.

Try out the application. Click Add, enter 'John Doe' for the name and 'john@johndoe.de' for the email. Click OK. The list widget should now contain the new item.

Displaying the Selected Item

When the user selects an item in the list widget, we would like to update the nameLabel and emailLabel at the bottom of the form. This behavior requires another slot to be added to the AddressBook class.

Qt For Visual Studio

In the addressbook.h file, add the following code in the private slots section of the class:

Then, add the block of code below to addressbook.cpp:

Thanks to the naming convention, this slot will automatically be connected to addressList's QListWidget::currentItemChanged() signal, and will be invoked whenever the selected item in the list changes.

Using Qt In Visual Studio

Adding Functionality for the Delete Button

Similar to the Add button, we implement a slot for the Delete button. Open the addressbook.h file and add a new slot declaration on_deleteButton_clicked(). Then open addressbook.cpp and add the slot definition for on_deleteButton_clicked(). Type the following code in the slot's body:

Your application is now complete!

Creating Qt Project File

If you want to build this application on other platforms, you need to create a .pro file for the project. A simple way to do this is to let the Visual Studio Add-in create a basic .pro file for you by clicking Qt|Create Basic .pro File. When the Export Project dialog shows up, ensure that the Create .pri File option is checked, then click OK. Visual Studio will then ask you where to save the .pri file. The default location and name is usually sufficient, so just click Save. For more information about .pro files and their associated .pri files, see Managing Projects.

That's it! You should now have a working .pro file and .pri file for your project. For more complex projects, manually editing the .pro file is required to make it work on all plaforms; however, for our simple project the generated .pro file is sufficient.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.