我的插槽未在 Qt Creator 信号/插槽编辑器中列出

发布于 2024-10-07 06:00:11 字数 460 浏览 0 评论 0原文

我创建了一个 Qt4 Gui 应用程序。我有主窗口。我在主窗口的中央小部件上放置了一个 QStackedWidget 和两个 QPushButton。我使用 QtCreator 作为我的 IDE。

在附图中,显示的堆叠小部件有两个页面,两个按钮 1 和 2 分别用于导航到堆叠小部件的第一页和第二页。

问题一: 当我打开信号/槽编辑器时,我选择了 sender=button1 和 signal=clicked,然后选择了 receive=stackedWidget 和 slot=? 。它应该是 setCurrentIndex() 但它没有列在下拉列表中。

问题2:alt text 在 QtCreator 的右侧对象面板中标有“拒绝符号”。我不知道为什么会有这些符号?有什么问题吗?

我附上下面的屏幕截图。如果需要更多详细信息,请告诉我。

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:alt text
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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的夜不怕黑 2024-10-14 06:00:11

我也在学习QT和QT Designer,也遇到了同样的问题。在互联网上进行了坚决的搜索,发现其他几个人也有同样的问题,但没有答案。你可能认为现在有人已经解释了。叹。

无论如何,问题是按钮发送的信号与堆叠小部件上的“setCurrentIndex(int)”插槽的签名不匹配,因此“setCurrentIndex(int)”不会显示在菜单中当人们尝试使用按钮“clicked()”信号时。也就是说,“clicked()”没有参数,而“setCurrentIndex(int)”只有一个整数参数,因此它们具有不同的签名。

在我的项目中,我试图将菜单项连接到堆叠的小部件,以便在选择菜单项时显示其中包含的小部件之一。菜单项只有“triggered()”信号,没有“triggered(int)”信号,并且 QStackedWidget 的“setCurrentIndex(int)”槽需要一个在其签名中具有单个整数参数的信号。

换句话说,你不能直接做你想做的事。

这是我在代码中解决这个问题的方法。请记住,我正在用 C# 编写 Qt 应用程序,使用 MonoDevelop(在 Linux 下进行 C# 开发)和 Qyoto(这是 Qt 的 C# 接口)。

创建主窗口(并将其分配给名为“layout”的变量)后,我这样做了:

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

这会导致我的菜单项在触发时调用 showSomeView() 函数。

然后我写了

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

现在它达到了我的意思!

您项目语言的解决方案应该与此类似。不幸的是,信号/槽连接必须在代码中设置,而不是在 QT Designer 的 GUI 中,但我不知道还能怎么做。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文