Getting Errors When Using Qt Creator to Create Signals and Slots

I created a new dialog using Qt Creator (version 4.7.0) - one of the template forms (with the "OK" and "Cancel" buttons).

I want the user to enter some data in the form, and then when they click "OK", he saves this information. Thus, I looked and saw that when I click "OK", it sends and signals a slot for receiving a dialogue.

So, I right-clicked on the dialog in the project view and selected "Go to slot ...". I clicked on the β€œaccepted” option, which placed the on_Dialog_accepted () method in the dialogs class. However, when I run the program and open a dialog, I get an error message in my console sayingQMetaObject::connectSlotsByName: No matching signal for on_Dialog_accepted()

So what have I done wrong?

I found documentation called connectSlotsByName, but nothing about any obvious errors that an inexperienced Qt developer might get.

+3
source share
2 answers

Right-clicking on the dialog in the project view until selecting "Go to slot ..." made a connection with dialog signals to a dialog slot that does not work with QMetaObject :: connectSlotsByName (), since this method searches for all child objects, but not for the object itself.

What you wanted to do was right-click on the OK button and then select "Go to slot ...". Then it will create a slot with the name of the widget of your button, and the connection will be completed correctly at runtime.

, QtDesigner "Go to slot..." . , Qt.

+2

, : . QtCreator. , . , .

QtCore, QMetaObject:: connectSlotsByName() , , ( QtCreator).

patch.

. , , bug Qt 5.1. . , QtCreator , Qt .

+2

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


All Articles