错误“没有这样的插槽” qt

发布于 2024-11-28 02:59:34 字数 1624 浏览 1 评论 0原文

我试图通过信号/插槽选项连接两个小部件,但我不断收到“不存在这样的插槽”的错误。事实上,在编写程序时,我使用 Ctrl + Space 只是为了确保不会犯任何拼写错误。

所以我有一个小部件:

renderArea.h

    class renderArea : public QGraphicsView
    {
        Q_OBJECT
    public:
        renderArea(QWidget *parent = 0);

    void addClothoid(float length, float startCurvature, float endCurvature);

    signals:
        void sendData(float length, float startCurvature, float endCurvature);

    };

renderArea.cpp

    void renderArea::addClothoid(float length, float startCurvature, float endCurvature)
    {
        ...

            emit sendData(length, startCurvature, endCurvature);
        }
    }

第二个小部件:

tableViewList.h

    class TableViewList: public QTableView
    {
        Q_OBJECT

    public:
        TableViewList(QWidget* parent = 0);

    protected slots:
        void onClothoidAdded(float length, float startCurvature, float endCurvature);
    };

tableViewList.cpp

    void TableViewList::onClothoidAdded(float length, float startCurvature, float endCurvature)
    {

    ...
    }

和主要小部件:

renderingwidget.cpp 我连接上面的两个:

    renderingWidget::renderingWidget(QWidget *parent) :
            QWidget(parent),
            ui(new Ui::renderingWidget)
    {
        ui->setupUi(this);

    connect(ui->graphicsView, SIGNAL(sendData(float,float,float)), ui->clothoidTable,
                SLOT(onClothoidAdded(float,float,float)));
    }

ui->graphicsView 已提升为 renderArea 和ui->clothoidTable 到 TableViewList。

那么为什么会出现这个错误呢?

I am trying to connect two widgets through the signals/slots option but I keep getting this error that 'no such slot' exists. The fact is that while writing the program I used Ctrl + Space just to be sure I don't make any typos.

so I have one widget:

renderArea.h


    class renderArea : public QGraphicsView
    {
        Q_OBJECT
    public:
        renderArea(QWidget *parent = 0);

    void addClothoid(float length, float startCurvature, float endCurvature);

    signals:
        void sendData(float length, float startCurvature, float endCurvature);

    };

renderArea.cpp


    void renderArea::addClothoid(float length, float startCurvature, float endCurvature)
    {
        ...

            emit sendData(length, startCurvature, endCurvature);
        }
    }

the 2nd widget:

tableViewList.h


    class TableViewList: public QTableView
    {
        Q_OBJECT

    public:
        TableViewList(QWidget* parent = 0);

    protected slots:
        void onClothoidAdded(float length, float startCurvature, float endCurvature);
    };

tableViewList.cpp


    void TableViewList::onClothoidAdded(float length, float startCurvature, float endCurvature)
    {

    ...
    }

and the main widget:

renderingwidget.cpp where i connect the 2 above:


    renderingWidget::renderingWidget(QWidget *parent) :
            QWidget(parent),
            ui(new Ui::renderingWidget)
    {
        ui->setupUi(this);

    connect(ui->graphicsView, SIGNAL(sendData(float,float,float)), ui->clothoidTable,
                SLOT(onClothoidAdded(float,float,float)));
    }

the ui->graphicsView has been promoted to renderArea and the ui->clothoidTable to the TableViewList.

So why could this error be appearing?

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

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

发布评论

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

评论(2

狠疯拽 2024-12-05 02:59:34

将信号/槽添加到类后是否重新生成了项目文件?根据您的构建系统,这是使事情正常运行所必需的。

Qt 需要预处理类头(它不会扫描 cpp 文件)以生成实现信号/槽行为的附加代码(对于信号/槽,它使用 MOC 编译器)。如果 Qt 不知道类 X 包含信号或槽,它将不会生成该类的元信息。

通过重新生成项目文件/Make 文件,Qt 将再次扫描所有文件并为 MOC 编译器生成必要的命令。

Did you re-generate your project files after adding the signal/slots to the class? Depending on your build system this is necessary to make things work.

Qt needs to pre-process the class headers (it does not scan in cpp files) to generate the additional code that implements the signal/slot behaviour (for signal/slots it's using the MOC compiler). If Qt is not aware that class X contains a signal or slot it will just not generate the meta information for that class.

By re-generating the project files/Make file Qt will scan all files again and generate the necessary commands for the MOC compiler.

苄①跕圉湢 2024-12-05 02:59:34

您的插槽受到保护,因此对 renderingWidget 不可见。如果您想从 TableViewList 外部设置与它的连接,则需要将其公开。

Your slot is protected and therefore not visible to renderingWidget. You will need to make it public if you want to setup a connection to it from outside TableViewList.

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