公告版位
需要找什麼嗎? 左邊分類或許可以幫助你...

目前分類:[程式語言] C++ (10)

瀏覽方式: 標題列表 簡短摘要

CQtwindows32ToolsQtCreatorbinqtcreator_process_stub.exe  


#include<QCoreApplication>
#include<QDebug>
#include<QTextStream>
 
int main(int argc, char*argv[]) {
 
    QCoreApplication a(argc,argv);
 
    qDebug()<<"PleaseKeyIn:";
    qDebug()<<"----------------------------";
 
    while(1){
        QTextStream qtin (stdin);
        QString line = qtin.readLine();
 
        qDebug()<<"KeyIn:"<<line.toStdString().data();
    }
 
    return a.exec();
}
 
 
 
 

黃彥霖 發表在 痞客邦 留言(0) 人氣()

MainWindow  

*.pro 文件加入:

    QT += core   gui   multimediamulti   mediawidgets


------------------------------------------------------------------------

mainwindow.h 檔案:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QCameraImageCapture>
#include <QCameraViewfinder>
#include <QCamera>
#include <QTimer>
#include <QImage>
#include <QDebug>
#include <QFile>
 
namespace Ui{
    class MainWindow;
}
 
class MainWindow : public QMainWindow {
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget*parent=0);
    ~MainWindow();
 
private:
    Ui::MainWindow*ui;
    QCameraImageCapture*ic;
 
privateslots:
    void displayImage(intid,QImageimage);
    void videoFrameCapture();
};
 
#endif //MAINWINDOW_H

------------------------------------------------------------------------

黃彥霖 發表在 痞客邦 留言(0) 人氣()

CQtQt5.5.1ToolsQtCreatorbinqtcreator_process_stub.exe  

main.cpp

#include "cat.h"
 
#include <QCoreApplication>
 
int main(int argc, char * argv[]) {
 
    QCoreApplication a(argc,argv);
 
    Cat c;
    c.name = "A";
    c.start();              // 呼叫 run()
 
    Cat c2;
    c2.name = "B";
    c2.start();            // 呼叫 run()
 
    return a.exec();
}

---------------------------------------------------------------------
Cat.h

#ifndefCAT_H
#defineCAT_H
 
#include <QThread>
#include <QDebug>
 
class Cat : public QThread {
    public:
        Cat();
        void run();
        QString name;
};
 
#endif//CAT_H
 

---------------------------------------------------------------------
Cat.cpp

#include "cat.h"
 
Cat::Cat(){
}
 
void Cat::run(){
    for(int i=1; i<=100; i++){
        qDebug() << name << i;
        QThread::currentThread()->msleep(100); // 暫停 0.1 秒
    }
}
 
 

黃彥霖 發表在 痞客邦 留言(0) 人氣()

PrtScr capture_3本範例環境:

作業系統:Win 10
編譯器:MSVC 2013
開發環境:Qt Creator 3.5.1
Qt 版本:5.5.1

注意:如果是用 MSVC 編譯器,可以播 mp4 檔案;MinGW 則不能播 mp4 檔案,但可以播 avi 與 mpg 檔案

1. 先新增一個 Qt Widgets Application 專案

黃彥霖 發表在 痞客邦 留言(0) 人氣()

常用參數:

    QIODevice::ReadWrite
    QIODevice::ReadOnly
    QIODevice::WriteOnly
    QIODevice::Text
    QIODevice::Append

檔案讀取:

黃彥霖 發表在 痞客邦 留言(0) 人氣()

寫入Json 物件:

#include<QCoreApplication>
#include<QJsonDocument>
#include<QJsonObject>
#include<QJsonValue>
#include<QJsonArray>
#include<QDebug>
 
int main(int argc,char * argv[]) {
 
    QCoreApplication a(argc,argv);
 
    QJsonObject jsonObj;
 
    jsonObj.insert("A","aaa");
    jsonObj.insert("B","bbb");
 
 
    //輸出:
 
    QJsonDocument doc(jsonObj);
    QString strJson(doc.toJson()); 
    qDebug()<<strJson.toStdString().data();
 
    return a.exec();
}
  

輸出結果:

PrtScr capture_3

 ----------------------------------------------------------------------------------------------------------

Json 物件單行輸出:

#include<QCoreApplication>
#include<QJsonDocument>
#include<QJsonObject>
#include<QJsonValue>
#include<QJsonArray>
#include<QDebug>
 
 
int main(int argc, char * argv[]){
 
    QCoreApplication a(argc,argv);
 
    QJsonObject jsonObj;
 
    jsonObj.insert("A","aaa");
    jsonObj.insert("B","bbb");
 
 
    //輸出:
 
    QJsonDocument doc(jsonObj);
    QString strJson(doc.toJson(QJsonDocument::Compact)); 
    qDebug()<<strJson.toStdString().data();
 
    return a.exec();
}

輸出結果:

CQtQt5.5.1ToolsQtCreatorbinqtcreator_process_stub.exe

 ----------------------------------------------------------------------------------------------------------

Json 巢狀物件:

#include<QCoreApplication>
#include<QJsonDocument>
#include<QJsonObject>
#include<QJsonValue>
#include<QJsonArray>
#include<QDebug>
 
 
int main(int argc, char * argv[]){
 
    QCoreApplication a(argc,argv);
 
 
    QJsonObject country; 
    country.insert("Japan","HelloKitty");
 
    QJsonObject city; 
    city.insert("Taipei","101");  
    country.insert("Taiwan",city); 
 
 
    //輸出:
 
    QJsonDocument doc(country); 
    QString strJson(doc.toJson(QJsonDocument::Compact)); 
    qDebug()<<strJson.toStdString().data();
 
    return a.exec();
}

輸出結果:
CQtQt5.5.1ToolsQtCreatorbinqtcreator_process_stub.exe_2  

 ----------------------------------------------------------------------------------------------------------

Json 陣列:

黃彥霖 發表在 痞客邦 留言(1) 人氣()

#include<QCoreApplication>
#include<QDebug>
#include<QtNetwork/QNetworkAccessManager>
#include<QtNetwork/QNetworkRequest>
#include<QtNetwork/QNetworkReply>
#include<QUrl>
#include<QUrlQuery>
#include<QFile>
 
 
void sendRequest(){
 
    QEventLoop eventLoop;
    QNetworkAccessManager mgr;
 
    QObject::connect(&mgr,SIGNAL(finished(QNetworkReply*)),&eventLoop,SLOT(quit()));
 
    QNetworkRequest req(QUrl(QString("http://i39.tinypic.com/1yn3wx.jpg")));
    QNetworkReply * reply = mgr.get(req);
 
    eventLoop.exec();
 
    if(reply->error()==QNetworkReply::NoError){
        //連接成功
 
        qDebug()<<"Download...";
 
        QFile * file = new QFile("C:/Test/downloaded.jpg");
        if(file->open(QFile::Append)) {
            file->write(reply->readAll());
            file->flush();
            file->close();
        }
        delete file;
 
        qDebug() << "ok";
 
    }else{
        //連接失敗
        qDebug() << "Failure" <<reply -> errorString();
    }
    delete reply;
}
 
intmain(int argc, char * argv[]) {
    QCoreApplication a(argc,argv);
    sendRequest();
    return a.exec();
}
 

黃彥霖 發表在 痞客邦 留言(0) 人氣()

PrtScr capture


#include <QCoreApplication>
#include <QDebug>
#include "windows.h"                // Windows
// #include "#include <sys/stat.h>" // Linux
 
 
intmain(int argc, char * argv[]){
 
    QCoreApplication a(argc,argv);
 
    QString msg;
 
    for(int i=1;i<=10;i++){
        msg.sprintf("Hello:%d",i);
        qDebug()<<msg.toStdString().c_str();
        Sleep(1000);
    }
 
    returna.exec();
}
 

也可以參考:http://blog.csdn.net/dbzhang800/article/details/6300425

 

 


黃彥霖 發表在 痞客邦 留言(0) 人氣()

CQtQt5.5.1ToolsQtCreatorbinqtcreator_process_stub.exe

#include<QCoreApplication>
#include<QDebug>
#include<QtNetwork/QNetworkAccessManager>
#include<QtNetwork/QNetworkRequest>
#include<QtNetwork/QNetworkReply>
#include<QUrl>
#include<QUrlQuery>
 
void sendRequest() {
 
    QEventLoop eventLoop;
    QNetworkAccessManager mgr;
 
    QObject::connect(&mgr,SIGNAL(finished(QNetworkReply*)),&eventLoop,SLOT(quit()));
 
    QNetworkRequest req(QUrl(QString("http://ip.jsontest.com/")));
    QNetworkReply * reply=mgr.get(req);
 
    eventLoop.exec();
 
    if(reply->error()==QNetworkReply::NoError){
        //連接成功
        qDebug()<<"Success"<<reply->readAll();
    } else {
        //連接失敗
        qDebug()<<"Failure"<<reply->errorString();
    }
    delete reply;
}
 
int main(int argc, char * argv[]) {
     QCoreApplication a(argc, argv);
     sendRequest();
     return a.exec();
}
 

黃彥霖 發表在 痞客邦 留言(0) 人氣()

安安你好  
 
#include<QApplication>
#include<QLabel>
 
intmain(intargc,char*argv[]) {
 
    QApplicationa(argc,argv);
 
    QWidget*w=newQWidget();
 
    QLabeltxt(w);
    txt.setText("世界你好");
 
    w->setWindowTitle("安安你好");
    w->setMinimumWidth(300);
    w->setMinimumHeight(200);
    w->show();
 
    returna.exec();
}



安安你好_2  

#include<QApplication>
#include<QLabel>
#include<QVBoxLayout>
#include<QPushButton>
 
intmain(intargc,char*argv[]){
 
    QApplicationa(argc,argv);
 
    QWidget*w=newQWidget();
 
    //建立文字(Label)
    QLabeltxt(w);
    txt.setText("世界你好");
 
    //建立按鈕(Button)
    QPushButton*b=newQPushButton(QObject::tr("關閉拉"),w);
    QObject::connect(b,SIGNAL(clicked()),w,SLOT(close()));//按下按鈕關閉程式
 
    //LabelButton加入垂直Layout
    QVBoxLayout*layout=newQVBoxLayout;
    layout->addWidget(&txt);
    layout->addWidget(b);
 
    //Layout加入Widget
    w->setLayout(layout);
 
    //設定:視窗標題、大小
    w->setWindowTitle("安安你好");
    w->setMinimumWidth(300);
    w->setMinimumHeight(200);
 
    //顯示視窗
    w->show();
 
    returna.exec();
}
 
 
 

黃彥霖 發表在 痞客邦 留言(0) 人氣()