QT改错,#include "widget.h" #include "ui_widget.h" #include <QTime> #include <QTimer> #include <QPixmap> #include <iostream> #include <string> #include <QDebug> Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); this->count = 0; this->tm = new QTimer(this); this->tm->start(1000); this->ui->label_2->setText(QTime::currentTime().toString("yyyy-MM-dd hh:mm:ss")); QTime time(0,0,0,0); this->ui->timeNumber->display(time.toString("hh:mm:ss")); //初始化label QPixmap pic(":/images/1.jpg"); this->ui->label->setPixmap(pic); for (int i = 1; i <= 9; i ++){ QString file_path = ":/images/"; file_path = QString::number(i) + ".jpg"; ph_set.push_back(file_path); qDebug() << file_path << endl; } connect(this->tm,&QTimer::timeout,this,&Widget::update_tm); } Widget::~Widget() { delete ui; } void Widget::update_tm() { this->count ++; QTime time(0,0,0,0); this->ui->timeNumber->display(time.addSecs(count).toString("mm:ss")); this->ui->label_2->setText(QTime::currentTime().toString("hh:mm:ss")); } void Widget::on_beforeButton_clicked() { } void Widget::on_afterButton_clicked() { }
时间: 2023-06-17 07:07:03 浏览: 84
这段代码有一些问题。首先,头文件`#include <iostream>`和`#include <string>`似乎没有被使用到,可以删掉。其次,在`on_beforeButton_clicked()`和`on_afterButton_clicked()`两个函数中,没有编写具体的实现代码。最后,`qDebug()`函数在输出调试信息时不需要加上`<< endl`,因为`qDebug()`函数会自动在每一条输出信息后加上一个换行符,所以这里需要将`endl`删除。
下面是改错后的代码:
```
#include "widget.h"
#include "ui_widget.h"
#include <QTime>
#include <QTimer>
#include <QPixmap>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->count = 0;
this->tm = new QTimer(this);
this->tm->start(1000);
this->ui->label_2->setText(QTime::currentTime().toString("yyyy-MM-dd hh:mm:ss"));
QTime time(0,0,0,0);
this->ui->timeNumber->display(time.toString("hh:mm:ss"));
//初始化label
QPixmap pic(":/images/1.jpg");
this->ui->label->setPixmap(pic);
for (int i = 1; i <= 9; i ++) {
QString file_path = ":/images/";
file_path = QString::number(i) + ".jpg";
ph_set.push_back(file_path);
qDebug() << file_path;
}
connect(this->tm, &QTimer::timeout, this, &Widget::update_tm);
}
Widget::~Widget()
{
delete ui;
}
void Widget::update_tm()
{
this->count ++;
QTime time(0,0,0,0);
this->ui->timeNumber->display(time.addSecs(count).toString("mm:ss"));
this->ui->label_2->setText(QTime::currentTime().toString("hh:mm:ss"));
}
void Widget::on_beforeButton_clicked()
{
// 在这里编写具体实现代码
}
void Widget::on_afterButton_clicked()
{
// 在这里编写具体实现代码
}
```
阅读全文