windows程序设计2017考试题01

1.Mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
static int v=0;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::timerEvent(QTimerEvent *event)
{
    v++;
    ui->lineEdit->setText(QString::number(v));
    ui->horizontalSlider->setValue(v);
    if(v==100)
    {
        v=0;
    }
}

void MainWindow::on_pushButton_clicked()
{
    QString str=ui->lineEdit->text();
    int val=str.toInt();
    v=val;
    ui->horizontalSlider->setValue(v);
}

void MainWindow::on_pushButton_2_clicked()
{
    timeId=this->startTimer(1000);
    //QObject::connect(ui->lineEdit,SINGAL(valueChanged(int)),ui->horizontalSlider,SLOT(SetValue(int)));
}



 2.MAINWINDOW.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include 
#include 
#include 
#include


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();


private:
    int timeId;
    void timerEvent(QTimerEvent *event);
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

windows程序设计2017考试题01_第1张图片
 

你可能感兴趣的:(Windows程序设计)