1

I have a simple setup to change a label on a timed interval, for testing purposes. It seems that the signal does not ever get emitted. I'm using Visual Studio 2010 with the Qt add-in. Here is my setup...

Window::Window(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
{
    ui.setupUi(this);
    my_label = new QLabel();

    timer = new QTimer(this);
    timer->setInterval(1000);
    connect(timer, SIGNAL(timeout()), this, SLOT(nextFrame()));
}

void Window::nextFrame()
{
    static int i = 0;
    std::stringstream ss;

    ss << "C:/files/" << i << ".txt";
    QString qstr = QString::fromStdString(ss.str());
    ui.label->setText(qstr);

    ss.str("");
    i++;
    repaint();
}

And in the header file,

public:
    Window(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~Window();

public slots:
    void nextFrame();

private:
    Ui::TrackerClass ui;
    QTimer *timer;
};

Why is the slot nextFrame() never being triggered?

0

2 Answers 2

2

There is nothing in this code which calls start() and so based on this code nextFrame() would never be triggered by timeout().

1
  • 1
    That's exactly it. D'oh! I was following a tutorial and missed that :) Thanks
    – zebra
    Apr 30, 2012 at 19:08
0

Couple of things I think I can help with:

  1. nextFrame() is a SLOT. SLOTs don't emit. They receive. SIGNALS emit. Not trying to be rude, just want to be clear on this as it's an important distinction. (in this case the signal is timeout() )
  2. you need to have a start() to begin the timer. something like the line below would seem to do the trick:

Hope this helps clear up some confusion.

timer->start(1000);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.