PDA

View Full Version : QTimer not calling slot



been_1990
24th October 2010, 19:50
I have a QObject subclass that sets a timer to call a slot. But that never happens.

shot.h:

#ifndef SHOT_H
#define SHOT_H

#include <QObject>
#include <QTimer>


class Shot : public QObject
{
Q_OBJECT
public:
explicit Shot(QObject *parent = 0);
private:
QTimer *timer;
public slots:
void updatePos();

};

#endif // SHOT_H

shot.cpp:

#include "shot.h"
#include <QDebug>

Shot::Shot(QObject *parent) :
QObject(parent)
{
timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(updatePos()));
timer->setInterval(0);
timer->start();
}

void Shot::updatePos()
{
//timer never reaches here...
}

tbscope
24th October 2010, 19:58
Does the slot really exist? Is the file processed by moc?

wysota
24th October 2010, 21:48
Is the event loop running?

been_1990
25th October 2010, 00:10
Does the slot really exist? Is the file processed by moc?
Yes, it does:

public slots:
void updatePos();



Is the event loop running?

Hmmm.. I think so. This is a class I call to create an item when needed.


if(btn1){
ui->lineEdit->setText("cliked");
Shot tiro;
}

wysota
25th October 2010, 00:26
Think what is the scope of your "tiro" object and what happens to it when line #4 of the code is reached.

been_1990
25th October 2010, 00:39
@#!!%&* I should really take a shot on the head.:mad:

Scope, I always forget.... Thanks for the patience.:o

BTW, why is QGraphicsView so slow when updating an item's position?

wysota
25th October 2010, 06:20
BTW, why is QGraphicsView so slow when updating an item's position?
Because you are not using it correctly.

been_1990
25th October 2010, 13:39
I'm using setPos(x,y) to update it's position. Isn't that correct? I checked out the "40000 Chips" example, and copied some settings from it's QGraphicsView:

graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainte rState);
graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewport Update);
But it still goes slow. Where can I see an example of correct implementation of QGraphicsView with changing elements positions(not drag-'n-drop)

wysota
25th October 2010, 14:31
There is no correct implementation of Graphics View bla bla bla. What is correct depends on a case-by-case basis.