Getting errors when using Qt Creator to create signals and slots - qt

I've created a new dialog using Qt Creator (version 4.7.0) - one of the templated forms (with an OK and a Cancel button).
I want the user to enter some data on the form and then when they click OK, it saves that information. So I had a look, and saw that when the OK button is clicked, it sends and signal to the dialog's accept slot.
So I right clicked on the dialog in the design view, and selected "Go to slot...". I clicked on the "accepted" option, which dropped an on_Dialog_accepted() method into the dialogs class. However, when I run the program and open the dialog, I get an error in my console saying QMetaObject::connectSlotsByName: No matching signal for on_Dialog_accepted()
So what did I do wrong?
I've found documentation on the connectSlotsByName - but nothing about any obvious pratfalls that an inexperienced Qt-developer can get themselves into.

Right-clicking on the dialog in the design view prior to selecting "Go to slot..." made a connection from the dialog's signals to the dialog's slot, which doesn't work with QMetaObject::connectSlotsByName(), since that method searches for all child objects, but not for the object itself.
What you wanted to do actually is right-clicking on the OK button, then selecting "Go to slot..." from there. It will then create a slot with the name of your button widget, and the connection will be made correctly at run-time.
It makes no sense that QtDesigner lets you select "Go to slot..." from the Dialog. You might want to file a bug to Qt's devs for that.

It is basically just as Fred explained: you did not do anything wrong. This is a QtCreator bug. And a pretty old one for that matter. Unfortunately, even two years later nothing in that regard has changed.
The assignee of the aforementioned bug decided to sort of redirect it to this QtCore bug, which simply asks for QMetaObject::connectSlotsByName() to be changed in a way that it also processes the passed object and not only its children (thereby fixing the QtCreator issue).
I had a look at the source and submitted a trivial patch.
Update: The patch got accepted, meaning this bug is going to be fixed in Qt 5.1. Note: it is not relevant which version of QtCreator your are using but which version of Qt you link your code to.

Related

Workaround Qt bug Combobox dropdown appear behind window

Right now I have a small tool app that runs in the icon tray. When I click on the icon, the app goes into "windowstayontophint" mode. I added a Combo Box on this window. But when I click elsewhere on desktop, and then click the combo box, the drop down window goes to the back of the window. This seems to be a known bug as reported here:
https://bugreports.qt.io/browse/QTBUG-61804
Is there a workaround for this? I am using Qt 5.9.1.
EDIT: Add some code:
This in MainWindow constructor:
Qt::WindowFlags flags = this->windowFlags();
this->setWindowFlags(flags|Qt::WindowStaysOnTopHint);
Then I put a QComboBox in the mainwindow with preloaded items. First time click, the dropdown appears on top as normal. Then I click onn desktop and then back on the mainwindow and combobox. And drop down becomes at the back of mainwindow. CLick on the link above to see what I mean. The bug report also provide screenshot of what is happening.
Nobody want to put an answer, so I answer this myself.
ANSWER: Update to latest Qt.
It did not work for me because I was having trouble updating (noob here). What basically happened was that Selecting "Update" option on Maintenance Tool does not update SDK from 5.9.1 to 5.10.1. It only update certain things like Qt Creator.
I needed to choose "Add or remove Components" and then adding Qt 5.10.1, but only check the MinGW 32bit only. (Uncheck all others otherwise you need them (like android or other)).
Even after that, you also need to manually download CMake (get it from cmake.com) and set it in "Manage Kits" in Qt Creator.

How to set a Slot receiving every Widget action in Qt

Suppose I've a Qt app based on QWidget, in which I'd like to obtain a "feedback" everytime I press a QPushButton, I rotate a QDial, I press a mouse button. My question is: how can I set a slot that informs me everytime something happened inside my app built for a touchscreen, in which I need to know when user does something on it.
MousePressEvent partially solves my problem; so when user touches the screen, MousePressEvent warns me about it. Problem is related to widgets as QPushButtons or QDials.
At the moment, I've already arranged my widgets with a lot of subwidgets; number of pushbutton is about 300. How can obtain triggering signal when one of them is pressed without re-edit every single button?
You can use an "event filter" that is installed on QApplication instance. This filter will receive all the events in your application, afterwards you can check event type and object type to pick the events you are interested in. See my answer to another question here for details.

PyQt5 - Signals&Slots - How to enable a button through content change of lineEdit?

since there isn't any useful How-To for beginners of PyQt5, I'm stuck with a little problem about signals & slots.
I do have a lineEdit which will get a directory path by a dialog (which works fine).
If one starts the program this lineEdit is empty by default and that's ok. A button, which shall generate a file list and show it in a list view, exists. It's functionality is implemented already and working fine. This button by default is disabled when the program is started for the first time.
What I want to do now is, enabling the button when something is entered at the lineEdit and disabling it when the content is removed.
I gave it a shot with this:
self.lineEdit_SelectedDirectory.editingFinished.connect(self.pushButton_CreateFileList.setEnabled)
but I get the error that it has not enough arguments, which might be clear because there aren't any provided in this code line.
Again, this was just a guess. How would one do this?
I would love something which takes the content into account like that, that it decides whether the content is empty or not and than sets the appropriate value to the button.
thx in advance for the help.
Christian
Looks like you want the textChanged signal, since that sends the current text:
self.lineEdit_SelectedDirectory.textChanged.connect(
lambda text: self.pushButton_CreateFileList.setEnabled(bool(text)))

FlexMonkey Issue with TitleWindow Popups

We are currently testing parts of our application that open in popup windows. These windows are subclasses of TitleWindow. The issue we now run into is that the popups seems to be registered multiple times and that tests are sometimes executed on popups that have already been closed (or so it seems).
I thought this had to do with the way we closed and removed our popups, but I can't really spot any problems there. After looking into the FlexMonkey source code, I saw that there is an explicit check for "TitleWindow" in the ADDED_TO_STAGE handler, after which the popup is added as an application window. But the popup never seems to be removed from the "_windows" collection. As a result, when you open the tree view in FlexMonkey, there are several instances of the same popup window class. This probably also explains why our tests sometimes do not seem to run (visually), but execute and verify correctly, as they are ran on a hidden instance of a popup. I would expect the MonkeyAutomationManager to also listen to REMOVED_FROM_STAGE events and remove the popup when it is closed.
Am I missing something here or is this an (known) issue?
My guess is that it isn't an issue, it's simply that your code isn't properly cleaning the object and removing it from the display list. You also need to remember that garbage collection does not run right after you remove something from the stage. It could be possible that your window, even if it has been removed from the stage is in fact still listening and responding to events.

Signal and slot connection in .ui

I have started to play a little with Qt 4. And then I have come across a problem with the Qt Designer.
In the Signal/Slots editor I can only setup the connections that are listed there, and not all the slots are listed.
If I try to add it manualy in the .ui file, the connection would not work.
If I add it in the ui_*.h file it works fine, but then the connection is deleted when I change the design.
Does anyone have any good tips to how I can get around this bug? Or to ask another way:
How can I make the Qt Designer list all the available slots?
By default not all signals/slots are shown. You could try checking the "show signals and slots inheritied from ...." checkbox in the lower left hand corder of the "Configure Connection" dialog that comes up when you try to create a signal.
Beyond that, you can either do what Marcin said and use auto-connections, or manually write connect statements in the constructor of the object that uses the ui.
You might try to use uic's autoconnecting feature.
However you won't be able to see all available slots but if you use the same name in both Designer and code - they should automatically be connected.

Resources