9.9.1. QTimer

[ fromfile: timers.xml id: timers ]

Figure 9.24. Speed-reader UML

Speed-reader UML

Example 9.17. src/timer/speed-reader/mainwindow.h

[ . . . . ]
class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    explicit MainWindow(QWidget* parent = 0);
    ~MainWindow();
protected:
    void changeEvent(QEvent* e);
    void processTrial();
private:
    Ui::MainWindow* ui;
private slots:
    void on_nextButton_clicked();
    void on_responseString_returnPressed();
    void on_startButton_clicked();
    void on_lengthSlider_valueChanged(int value);
    void on_exposureSlider_valueChanged(int value);
    void timerDisplayRandStr();
private:
    int m_expInterval;
    RandomString m_randStr;
    int m_trials;
    int m_correctChars;
    int m_totTrials;
    int m_totCorrectChars;
};
[ . . . . ]

Example 9.18. src/timer/speed-reader/mainwindow.cpp

[ . . . . ]
void MainWindow::processTrial() {
    //clear response text editor
    ui->responseString->setText("");
    //display the random string
    ui->targetString->setText(m_randStr.generateString());
    ui->responseString->setEnabled(false);
    ui->nextButton->setEnabled(false);
    //count the number of trials
    m_trials++;
    m_totTrials++;
    ui->nextButton->setText(QString("String %1").arg(m_trials));
    //begin exposure
    QTimer::singleShot(m_expInterval, this, SLOT(timerDisplayRandStr()));
}


void MainWindow::timerDisplayRandStr() {
    ui->targetString->setText(QString(""));
    //enable the response line editor and next button
    ui->responseString->setEnabled(true);
    ui->responseString->setFocus();
    ui->nextButton->setEnabled(true);
}

[ . . . . ]

Figure 9.25.  Speed Reader Screenshot

Speed Reader Screenshot