繁体   English   中英

Visual Studio中的Qt:连接插槽和信号不起作用

[英]Qt in visual studio: connecting slots and signals doesn't work

我已经安装了Qt和Qt for VS插件。 一切正常,UI应用程序可以编译并运行,但不能连接信号和插槽。 我的班级中有Q_OBJECT ,为了进行连接,我在构造函数中使用了以下代码:

connect(ui.mainTableView, SIGNAL(activated(const QModelIndex &)),
        this, SLOT(showDetail(const QModelIndex &)));

编辑:

showDetail方法:

void MyClass::showDetail(const QModelIndex &index)
{
    this->setWindowTitle("it works");
}

窗口标题未更改且未达到断点。

moc文件是在Generated Files目录中生成的,但是该类的moc文件为空(其他不是),我认为这是因为该类没有信号,而只有一个插槽。

即使Designer生成的连接也不起作用,并且connect方法的调用返回true

SIGNALSLOT宏中删除变量名称:

connect(ui.mainTableView, SIGNAL(activated(const QModelIndex &)),
    this, SLOT(showDetail(const QModelIndex &)));

有关更多详细信息,请仔细阅读有关QObject::connect文档。

moc是否正常工作? 那可以解释为什么connect没有做它的事情,但是其他一切都...

在Visual Studio 2012中,尝试使用时

connect(plot->xAxis, SIGNAL(rangeChanged(QCPRange)), plot->xAxis2, SLOT(setRange(QCPRange)));

我收到关于plotSIGNAL错误。

这是因为Visual Studio发现了错误的连接。 它在winsock.h找到了connect

为了纠正错误,我使用了QObject命名空间,如下所示:

QObject::connect(plot->xAxis, SIGNAL(rangeChanged(QCPRange)), plot->xAxis2, SLOT(setRange(QCPRange)));

供参考,以下是有关错误的信息。

对于第一个plot参数,错误为:

ERROR: argument of type "QCPAxis*" is incompatible with parameter of type "Socket".

对于第一个SIGNAL ,错误为:

ERROR: argument of type "cosnt Char*" is incompatible with parameter of type "const sockaddr*".

对于第二个plot参数,错误为:

ERROR: argument of type "QCPAxis*" is incompatible with parameter of type "int".

对于第二个SIGNAL ,错误为:

ERROR: too many arguments in function call.

结果:

哦,不,这真是一个愚蠢的问题,谢谢大家,所有答案都将我推向了解决方案,但是最后一步是要确定我平台上的项目仅通过双击而不是单击即可激活。 抱歉

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM