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.ipg"); 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 20:07:09 浏览: 191
代码中的图片路径有误,应该将第13行的 "ipg" 改为 "jpg"。正确的代码如下:
```
#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()
{
}
```
阅读全文