首先到QT網站上下載qt安裝文件Qt_SDK_Win_offline_v
然後下載一個qt
這時候可能會提示找不到g++不管繼續安裝
安裝完畢調整環境變量添加
PATH C:\ProgramData\Qt\bin\;C:\ProgramData\Qt\mingw\bin\;
QMAKESPEC win
QTDIR C:\ProgramData\Qt\
OK然後注銷或者重啟在命令行模式下分別輸入輸入 gcc make qmake看看能否找到
如果一切ok
cd /d d: (這個win
cd test
建立一個clock
在命令行輸入
qmake
qmake
make
然後就可以執行生成的文件test
cd debug
test
最終效果是
//clock
#ifndef CLOCK_H
#define CLOCK_H
#ifndef ALarm_H
#define ALarm_H
#include<QApplication>
#include<QTimer>
#include<QLCDNumber>
#include<QLabel>
#include <QVariant>
#include<QTimeEdit>
#include<QPushButton>
#include<QDialog>
#include <QMessageBox>
#include<QSystemTrayIcon>
#include<QAction>
#include<QMenu>
class Clock:public QDialog
{
Q_OBJECT
public:
Clock(QWidget * parent=
void init()
void layout()
void clock_connect()
void closeEvent(QCloseEvent *event)
public slots:
void clockChange()
void mini()
private:
QTimer * timer;
QLCDNumber * lcdNumber;//顯示當前時間
QPushButton *button;
QSystemTrayIcon *trayIcon;
QAction * restoreAct;
QAction * quitAct;
QMenu * trayIconMenu;
//QRect rect;
};
#endif
#endif // CLOCK_H
//clock
#include
Clock::Clock(QWidget * parent)
{
init()
layout()
clock_connect()
}
void Clock::init()
{
setWindowTitle(
setFixedSize(QSize(
timer=new QTimer;//控制lcd的時間刷新
lcdNumber=new QLCDNumber;//顯示當前時間
lcdNumber
lcdNumber
lcdNumber
button=new QPushButton(
trayIcon=new QSystemTrayIcon;
trayIcon
trayIcon
restoreAct=new QAction(QString::fromLocal
quitAct=new QAction(QString::fromLocal
trayIconMenu=new QMenu;
trayIconMenu
trayIconMenu
trayIcon
}
void Clock::layout()
{
lcdNumber
lcdNumber
button
button
button
button
};
void Clock::clock_connect()
{
connect(timer
timer
connect(button
};
// **************
// 顯示變化的時間
// **************
void Clock::clockChange()
{
lcdNumber
}
void Clock::mini()
{
hide()
}
void Clock::closeEvent(QCloseEvent *event)
{
QMessageBox::information(
}
//end
//main
#include
#include<QApplication>
int main(int argc
{
QApplication app(argc
Clock clock;
clock
return app
};
//end
From:http://tw.wingwit.com/Article/os/xtgl/201311/9569.html