Как выполнить код спустя время после того как программа была запущена? (Qt)

написал вот такой код:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::ops()
{
    ui->label->setText("tteexxtt");
}

QTimer::singleShot(3000, this, &MainWindow::ops);

и добавил в mainwindow.h:

private slots:
    void ops();

и поидеи программа должна запускаться, потом должен пройти отсчет 3 секунды и текст в label должен поменяться на tteexxtt, но я получаю ошибки:

mainwindow.cpp:22:9: C++ requires a type specifier for all declarations
mainwindow.cpp:22:26: Invalid use of 'this' outside of a non-static member function
mainwindow.cpp:22:45: 'ops' is a private member of 'MainWindow'
mainwindow.h:21:10: declared private here
mainwindow.cpp:21: ошибка: expected constructor, destructor, or type conversion before '(' token

как можно устранить данные ошибки?


Ответы (0 шт):