开发者

My slots not listed in Qt Creator Signal/Slot editor

I created a Qt4 Gui application. I have the main window. I put a QStackedWidget and two QPushButtons on the MainWindow's central widget. I am using QtCreator as my IDE.

In the attached image the shown stacked widget has two pages and the two pushButtons 1 and 2 are for开发者_开发百科 navigation to firstPage and SecondPage of the stacked widget respectively.

Problem 1: When I opened signal/slot editor I selected sender=button1 and signal=clicked, then receiver=stackedWidget and slot=? . It supposed to be setCurrentIndex() but its not listed in the drop down list.

Problem 2:

My slots not listed in Qt Creator Signal/Slot editor

In the right object panel of QtCreator there is marked the "Denied Symbols". I don't know why those symbols are there? Is there any problem ?

I am attaching the screenshot below. If any more details are required please let me know.


I too am learning QT and QT Designer, and ran into the same problem. A determined search of the Internet revealed several other people with the same question, and no answers. You'd think someone out there would have explained it by now. Sigh.

Anyway, the problem is that the signals sent by the push-buttons don't match the signature of the "setCurrentIndex(int)" slot on the stacked-widget, so "setCurrentIndex(int)" doesn't show up in the menu when one tries to use a push-button "clicked()" signal. That is, "clicked()" has no parameters, and "setCurrentIndex(int)" has a single integer parameter, therefore they have different signatures.

In my project, I was trying to connect menu items to a stacked widget, so that one of the contained widgets would be displayed when the menu item was selected. The menu items only have the "triggered()" signal, there's no "triggered(int)" signal, and QStackedWidget's "setCurrentIndex(int)" slot is expecting a signal that has a single integer parameter in its signature.

In other words, you can't do what you want, directly.

Here's how I solved it in my code. Keep in mind that I'm writing my Qt app in C#, using MonoDevelop (to do C# development under Linux) and Qyoto (which is a C# interface to Qt).

After creating my main window (and assiging it to a variable called "layout"), I did this:

QObject.Connect (layout.someMenuItem, SIGNAL("triggered()"), showSomeView);

This causes my menu item to call the showSomeView() function whenever it's triggered.

I then wrote

public void showSomeView()
{
    layout.stackedWidget.SetCurrentWidget(layout.someView);
}

Now it does what I mean!

The solution in your project's language should be similar to this. It's unfortunate that the signal/slot connections have to be set up in code, instead of in QT Designer's GUI, but I don't know how else to do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜