Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Creating a signal to slot connection in Qt Designer

From Wiki
Jump to: navigation, search

This article provides a step by step guide on how to use signal and slot mechanism in Qt Creator (from the Qt SDK). For fundamental information about signals and slots see Signals and Slots in Qt

Article Metadata
Code ExampleArticle
Created: rahulvala (06 Apr 2010)
Last edited: hamishwillee (09 Sep 2011)

Needs-update.pngThis article needs to be updated: If you found this article useful, please fix the problems below then delete the {{ArticleNeedsUpdate}} template from the article to remove this warning.

Reasons: hamishwillee (15 Apr 2011)

  • English is poor.
  • Links need to be checked
  • Most of this may be out of date with current Qt SDK - needs to be checked,

Contents

Introduction

Signal and slot is a mechanism used in Qt program by which the signal initiate one action and according to that action slot is affected or change its state.For the beginner of the Qt programmer this is difficult to understand the signal and slot style.

I have created the GUI application using signal and slot example. The steps are given below.

Steps

The below are steps for understanding signal and slot in GUI application in the Qt.

step-1

First of all open the Qt Creator window and start a new file or new project. In new project you need to new create the GUI application.

In GUI application blank .ui file is created where you can drop some widget from Qt designer window.

For more details about Qt Designer go to this link:Qt Designer

I have used one spin box and LCD number for better understanding of signal and slot.

You have to drag and drop the spin box and LCD number from Qt Designer list. After drag and drop final figure is given below.

Dragdropss.jpg

step-2

Now in this example spinbox is signal and LCD number is my slot, For making this I have to press F4 or click in the signal slot edit mode which is at the above of .ui file. See this in below figure.

Dragdropss2.jpg

step-3

After that your mouse is activated and you have to connect your signal means spinbox with slot means LCD number.When you put cursor in the spinbox it will covered by red line. After that you have to click on it and connect it with LCD number means slot by arrow.The final figure is given below.

Connection1.jpg

step-4

Now when you release the left key of your mouse you will get one window of configure connection which is given below. In which you have to connect signal action with slot reaction. In my example I have connected action as valueChanged(int) with reaction as display(int). See the below figure for this action.

Configconnection.jpg

step-5

Now final .ui file is available with blue boundary of spinbox and LCD nnumber,Also you can change the signal slot action using signal and slot editer which is given below in .ui file. The final figure is given below.

Signalsloteditor.jpg

step-6

Now you can save all your work and then run your project. You will get the below output. When you increase the value of spinbox the value of LCD number also increases and vice versa is true. See the below figure.

Signalslot.jpg

Code Example

Code (zip file) of this example is available at: File:Signalslotexample.zip

This page was last modified on 9 September 2011, at 03:26.
227 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×