读书人

No such signal解决方法

发布时间: 2013-01-04 10:04:16 作者: rapoo

No such signal
创建了工具栏,添加了第三个QAction时,在MainWindow类里


RectAction[2] = new QAction(tr("&Text"), this);
RectAction[2]->setStatusTip(tr("Inpute a Text."));
RectAction[2]->setIcon(QIcon("icons/encoding.png"));
connect(RectAction[2],SIGNAL(triggered()),this,SLOT(Text_selected()));
m_ptoolbar->addAction(RectAction[2]);/////
m_paction = RectAction[2];////m_paction 为全局变量,为了传到另一个类里

还是在MainWindow里,Text_selected槽函数

void MainWindow::Text_selected()
{
emit createText();//信号能进这里,发到另一个类里面
}


另一个类
MyPainter::MyPainter()//MyPainter里面做信号处理
{
connect(m_paction,SIGNAL(createText()),this,SLOT(recvtocreateText()),Qt::DirectConnection);//这里连接createText信号!!!
}
void MyPainter::recvtocreateText()///这个槽函数不被执行!!!!!
{
QLineEdit *edit = new QLineEdit(this);
edit->move(QPoint());//
edit->show();
}

报警告说:Object::connect: No such signal QAction::createText() in MyPainter.cpp:41
可是我的程序有这个信号啊!!!!!
[解决办法]
在MainWindow的构造函数里new出一个MyPainter对象,然后添加信号槽:
connect(mainwindow, SIGNAL(createText()),m_paction, SLOT(recvtocreateText()));

具体代码根据你程序改下,我随手写的

读书人网 >QT开发

热点推荐