- 創(chuàng)建一個線程,命名為ThreadOne,啟動線程,要求能夠打印1~10的所有數(shù)字,每隔1秒打印。
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
ThreadOne.h
#ifndef THREADONE_H
#define THREADONE_H
#include <QThread>
class ThreadOne : public QThread
{
Q_OBJECT
public:
explicit ThreadOne(QObject *parent = 0);
signals:
public slots:
protected:
virtual void run();
};
#endif // THREADONE_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ThreadOne.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ThreadOne* to = new ThreadOne(this);
to->start();
}
ThreadOne.cpp
#include "ThreadOne.h"
#include <QDebug>
#include <windows.h>
ThreadOne::ThreadOne(QObject *parent) : QThread(parent)
{
}
void ThreadOne::run()
{
int num = 1;
for(int i = 0; i < 10; i++) {
Sleep(1000);
qDebug() << num;
num++;
}
}
- 創(chuàng)建一個線程,命名為ThreadOne,完成倒計時的功能,從10秒開始倒數(shù),倒數(shù)結(jié)束后結(jié)束線程,打印“倒數(shù)結(jié)束”。
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
ThreadOne.h
#ifndef THREADONE_H
#define THREADONE_H
#include <QThread>
class ThreadOne : public QThread
{
Q_OBJECT
public:
explicit ThreadOne(QObject *parent = 0);
signals:
public slots:
protected:
virtual void run();
};
#endif // THREADONE_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "threadone.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ThreadOne* to = new ThreadOne(this);
to->start();
}
ThreadOne.cpp
#include "threadone.h"
#include <windows.h>
#include <QDebug>
ThreadOne::ThreadOne(QObject *parent) : QThread(parent)
{
}
void ThreadOne::run()
{
int num = 10;
for(int i = 10;i >= 0; i--) {
Sleep(1000);
qDebug() << num;
num--;
}
qDebug() << "倒數(shù)結(jié)束";
}
- 在終端使用sqlite3 創(chuàng)建學(xué)生表。
(1)該表有字段姓名,id(主鍵),成績(一門成績即可)
(2)使用終端插入3個學(xué)生
(3)通過終端查詢顯示插入的學(xué)生信息
演示:能夠顯示學(xué)生信息即可
C:\Users\Jantta>sqlite3 stu.db
SQLite version 3.14.1 2016-08-11 18:53:32
Enter ".help" for usage hints.
sqlite> CREATE TABLE student (
...> ID INT PRIMARY KEY,
...> score INT
...> );
sqlite>
sqlite> INSERT INTO student (ID, score)
...> VALUES (111,99),(222,86),(333,95);
sqlite> SELECT * FROM student;
111|99
222|86
333|95
sqlite>