读书人

QTimer连接槽的有关问题啊一直连接异常

发布时间: 2013-08-13 16:43:28 作者: rapoo

QTimer连接槽的问题啊,一直连接错误


MainWindow::MainWindow(QWidget *parent) : QWidget(parent), drawObstacle(this)
{
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

scene = new QGraphicsScene;
scene->setSceneRect(-300, -300, 600, 600);

//addEnemey();
circle = new Enemy;
circle->setPos(0,0);
scene->addItem(circle);

view = new QGraphicsView;
view->setScene(scene);
view->setRenderHint(QPainter::Antialiasing);
view->setBackgroundBrush(Qt::white);

view->show();

QTimer *timer = new QTimer(this);
QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(updateAdvance()));
timer->start(1000 / 33);
}



QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(updateAdvance()))一直报错,求解释啊
updateAdvance()已在mainwindow中声明槽了



错误:no matching function for call to 'MainWindow::connect(QTimer**, const char*, MainWindow* const, const char*)'

candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)

note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
[解决办法]
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(updateAdvance()));
timer都是new 出来的了,不要再取地址了

读书人网 >QT开发

热点推荐