Qt Signal 和 Slot 连接似乎不起作用

发布于 2025-01-03 14:22:14 字数 814 浏览 1 评论 0原文

我已经检查了很多次,但找不到我的错误。

在我的主类中,我有:

connect(userControl, SIGNAL(DataToPlot(std::vector<double>)), this, SLOT(test(std::vector<double>)));

在同一个类中,我有一个测试函数和原型:

public slots:
    void test(std::vector<double>);

void RelayduinoGuiThreading::test(std::vector<double> x)
{
    123;  // I put a breakpoint on this line to check when the slot is called.
}

在单独的线程中运行,我有以下内容:

signals:
    void DataToPlot(std::vector<double>);

somefunction
{
        // Stuff...

        std::vector<double> x;
        emit(DataToPlot(x));
}

现在,如果我将 std::vector 更改为 int 或 a双倍,它有效。

另外,#include 位于两个类头中。

我什至在我的项目中的其他地方发出 std::vector 并捕获信号并且没有任何问题。

非常感谢您的帮助。

谢谢。

I've checked this a heap of times and cannot find my error.

In my main class, I have:

connect(userControl, SIGNAL(DataToPlot(std::vector<double>)), this, SLOT(test(std::vector<double>)));

In the same class I have a test function and prototype:

public slots:
    void test(std::vector<double>);

void RelayduinoGuiThreading::test(std::vector<double> x)
{
    123;  // I put a breakpoint on this line to check when the slot is called.
}

Running in a seperate thread, I have the following:

signals:
    void DataToPlot(std::vector<double>);

somefunction
{
        // Stuff...

        std::vector<double> x;
        emit(DataToPlot(x));
}

Now here's the thing, if I change the std::vector to an int, or a double, it works.

Also, #include is in both class headers.

I even have somewhere else in my project where I emit an std::vector and catch the signal and have no problems with that.

Help is much appreciated.

Thank you.

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

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

发布评论

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

评论(2

鹿童谣 2025-01-10 14:22:14

正如 Qt Docu 中提到的

请注意,如果您打算在排队信号和槽连接或 QObject 的属性系统中使用该类型,则还必须调用 qRegisterMetaType(),因为名称是在运行时解析的。

因此,在您的主应用程序中,您必须调用:

qRegisterMetaType<std::vector<float> >("std::vector<float>");

并在您的 RelayduinoGuiThreading 头文件中(如 tibur 提到的):

Q_DECLARE_METATYPE(std::vector<float>);

这里是详细的文档

As it is mentioned in Qt Docu

Note that if you intend to use the type in queued signal and slot connections or in QObject's property system, you also have to call qRegisterMetaType() since the names are resolved at runtime.

So in your main application you have to call:

qRegisterMetaType<std::vector<float> >("std::vector<float>");

and in your RelayduinoGuiThreading header file (as tibur mentioned):

Q_DECLARE_METATYPE(std::vector<float>);

Here is the documentation in detail

阳光下的泡沫是彩色的 2025-01-10 14:22:14

尝试将其添加到您的 RelayduinoGuiThreading 标头中:

Q_DECLARE_METATYPE(std::vector<float>);

Try to add this in your RelayduinoGuiThreading header:

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