欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商教学与活动专区期货人生 → [原创]QT

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有6470人关注过本帖树形打印复制链接

主题:[原创]QT

帅哥哟,离线,有人找我吗?
z7c9
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
[原创]QT  发帖心情 Post By:2013/6/12 17:57:37 [显示全部帖子]

#include <QCoreApplication>
#include <QDate>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QDate startDate = QDate(2013,6,1);
    QDate endDate = QDate(2013,6,12);

    int b = startDate.daysTo(endDate);

    qDebug() << startDate;

    for(int i=1;i<b;++i){
        qDebug() << startDate.addDays(i);
    }

    qDebug() << endDate;

    return a.exec();
}


 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/6/12 22:19:03 [显示全部帖子]

#include <QCoreApplication>
#include <QDebug>
#include <QFile>

void readFromEnd(QString path)
{
    QFile file(path);
    file.open(QIODevice::ReadOnly);
    long len = file.size();
    long start = file.pos();
    long nextend = start + len - 1;
    file.seek(nextend);

    qint8 c;

    while(nextend>start){
        c = file.read(1).at(0);
        if(c=='\n'){
            qDebug() << file.readLine();
        }
        nextend--;
        file.seek(nextend);
        if(nextend==0){
            qDebug() << file.readLine();
        }
    }
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    readFromEnd("d:/AL01.csv");

    return a.exec();
}


 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/6/17 21:21:48 [显示全部帖子]

#include <QCoreApplication>
#include "src/SmtpMime"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
   
    SmtpClient smtp("smtp.139.com");
   
    smtp.setUser("888888");
    smtp.setPassword("888888");

    MimeMessage message;

    message.setSender(new EmailAddress("888888@139.com", "888888"));
    message.addRecipient(new EmailAddress("888888@139.com", "888888"));
    message.setSubject("888888");

    MimeText text;

    text.setText("888888");

    message.addPart(&text);

    smtp.connectToHost();
    smtp.login();
    smtp.sendMail(message);
    smtp.quit();

}


 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/6/17 21:22:37 [显示全部帖子]

 

#include <QCoreApplication>
#include <QDebug>
#include <QSettings>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QFile>

//测试注册表读写
void testRegistry(){
    QString path = "software\\weisoft\\金字塔\\settings";

    QSettings settings(path,QSettings::NativeFormat);

    settings.setValue("myid",12345);

    qDebug() << settings.value("myid").toInt();
}

//测试INI文件读写
void testINI(){
    QString path = "d:\\mysettings.ini";

    QSettings settings(path,QSettings::IniFormat);

    settings.setValue("myid",12345);

    qDebug() << settings.value("myid").toInt();
}

//测试全局变量读写
void testExtData(){
    QSettings settings("上海中期","北京营业部");
    settings.setValue("myid",12345);
    qDebug() << settings.value("myid").toInt();
}

//测试数据库读写
void testDatabase(){
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

    db.setDatabaseName("mytest.db");

    if(!db.open()){
        qDebug() << "db is not open";
    }else{
        QSqlQuery query;
        query.exec("create table main(id varchar)");
        query.exec("insert into main values(12345)");
        query.exec("select * from main");
        while(query.next()){
            qDebug() << query.value(0).toInt();
        }
    }
}

//测试CSV文件读写
void testCSV(){
    QFile csvFile("d:\\mytest.csv");

    if(csvFile.open(QIODevice::WriteOnly)){
        csvFile.write("1,2,3,4,5");
        csvFile.close();
    }

    if(csvFile.open(QIODevice::ReadOnly)){
        QTextStream in(&csvFile);
        QString result = in.readLine();
        qDebug() << result;
        csvFile.close();
    }
}

int main(int argc, char *argv[]){
    QCoreApplication a(argc, argv);
    testRegistry();
    testExtData();
    testINI();
    testDatabase();
    testCSV();
    return a.exec();
}


 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/6/23 7:15:25 [显示全部帖子]

#include "mytraderspi.h"
#include <QDebug>
#include <QString>
#include <QTextCodec>

char FRONT_ADDR[] = "tcp://sim-front1.ctp.shcifco.com:31205";
TThostFtdcBrokerIDType BROKER_ID = "1002";
TThostFtdcInvestorIDType INVESTOR_ID = "00000050";
TThostFtdcPasswordType PASSWORD_ID = "123456";


MyTraderSpi::MyTraderSpi()
{
    traderApi = CThostFtdcTraderApi::CreateFtdcTraderApi();
    traderApi->RegisterSpi(this);
    traderApi->SubscribePublicTopic(THOST_TERT_RESTART);
    traderApi->SubscribePrivateTopic(THOST_TERT_RESTART);
    traderApi->RegisterFront(FRONT_ADDR);
    traderApi->Init();
    traderApi->Join();
}

void MyTraderSpi::OnFrontConnected()
{
    CThostFtdcReqUserLoginField req;
    memset(&req,0,sizeof(req));
    strcpy(req.BrokerID,BROKER_ID);
    strcpy(req.UserID,INVESTOR_ID);
    strcpy(req.Password,PASSWORD_ID);
    traderApi->ReqUserLogin(&req,0);
}

void MyTraderSpi::OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
    if(bIsLast)
    {
        CThostFtdcSettlementInfoConfirmField req;
        memset(&req,0,sizeof(req));
        strcpy(req.BrokerID,BROKER_ID);
        strcpy(req.InvestorID,INVESTOR_ID);
        traderApi->ReqSettlementInfoConfirm(&req,0);
    }
}

void MyTraderSpi::OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
    if(bIsLast)
    {
        CThostFtdcQryInstrumentField req;
        memset(&req,0,sizeof(req));
        traderApi->ReqQryInstrument(&req,0);
    }
}

void MyTraderSpi::OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
     qDebug() << QString::fromLocal8Bit(pInstrument->InstrumentName);
}

 

[此贴子已经被作者于2013/6/23 7:15:57编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/6/23 7:19:03 [显示全部帖子]

#include <QCoreApplication>
#include "mytraderspi.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    MyTraderSpi spi;

    return a.exec();
}


 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/6/23 19:27:41 [显示全部帖子]

#include <QCoreApplication>
#include <QDebug>
#include <QTextCodec>
#include <QByteArray>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QByteArray encodedString;
    encodedString += "合约代码,";
    encodedString += "交易所代码,";
    encodedString += "合约名称,";
    encodedString += "合约在交易所的代码,";
    encodedString += "产品代码,";
    encodedString += "产品类型,";
    encodedString += "交割年份,";
    encodedString += "交割月,";
    encodedString += "市价单最大下单量,";
    encodedString += "市价单最小下单量,";
    encodedString += "限价单最大下单量,";
    encodedString += "限价单最小下单量,";
    encodedString += "合约数量乘数,";
    encodedString += "最小变动价位,";
    encodedString += "创建日,";
    encodedString += "上市日,";
    encodedString += "到期日,";
    encodedString += "开始交割日,";
    encodedString += "结束交割日,";
    encodedString += "合约生命周期状态,";
    encodedString += "当前是否交易,,";
    encodedString += "持仓类型,";
    encodedString += "持仓日期类型,";
    encodedString += "多头保证金率,";
    encodedString += "空头保证金率";

    QTextCodec *codec = QTextCodec::codecForName("GBK");
    QString string = codec->toUnicode(encodedString);
    qDebug() << string;
    return a.exec();
}
	


 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/6/23 22:38:59 [显示全部帖子]

#include "mytraderspi.h"
#include <QDebug>
#include <QByteArray>
#include <QString>
#include <QFile>


char FRONT_ADDR[] = "tcp://sim-front1.ctp.shcifco.com:31205";
TThostFtdcBrokerIDType BROKER_ID = "1002";
TThostFtdcInvestorIDType INVESTOR_ID = "00000050";
TThostFtdcPasswordType PASSWORD_ID = "123456";
int numOfContracts =0;


TraderSpi::TraderSpi()
{
    traderApi = CThostFtdcTraderApi::CreateFtdcTraderApi();
    traderApi->RegisterSpi(this);
    traderApi->SubscribePublicTopic(THOST_TERT_RESTART);
    traderApi->SubscribePrivateTopic(THOST_TERT_RESTART);
    traderApi->RegisterFront(FRONT_ADDR);
    traderApi->Init();
    traderApi->Join();
}

void TraderSpi::OnFrontConnected()
{
    CThostFtdcReqUserLoginField req;
    memset(&req,0,sizeof(req));
    strcpy(req.BrokerID,BROKER_ID);
    strcpy(req.UserID,INVESTOR_ID);
    strcpy(req.Password,PASSWORD_ID);
    traderApi->ReqUserLogin(&req,0);
}

void TraderSpi::OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
    if(bIsLast)
    {
        CThostFtdcSettlementInfoConfirmField req;
        memset(&req,0,sizeof(req));
        strcpy(req.BrokerID,BROKER_ID);
        strcpy(req.InvestorID,INVESTOR_ID);
        traderApi->ReqSettlementInfoConfirm(&req,0);
    }
}

void TraderSpi::OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
    if(bIsLast)
    {
        CThostFtdcQryInstrumentField req;
        memset(&req,0,sizeof(req));
        traderApi->ReqQryInstrument(&req,0);
    }
}

void TraderSpi::OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
    numOfContracts++;

    QFile file("d:/ooo.csv");

    if(file.open(QFile::Append))
    {
        if (numOfContracts==1)
        {
            QByteArray title;
            title += "合约代码,";
            title += "交易所代码,";
            title += "合约名称,";
            title += "合约在交易所的代码,";
            title += "产品代码,";
            title += "产品类型,";
            title += "交割年份,";
            title += "交割月,";
            title += "市价单最大下单量,";
            title += "市价单最小下单量,";
            title += "限价单最大下单量,";
            title += "限价单最小下单量,";
            title += "合约数量乘数,";
            title += "最小变动价位,";
            title += "创建日,";
            title += "上市日,";
            title += "到期日,";
            title += "开始交割日,";
            title += "结束交割日,";
            title += "合约生命周期状态,";
            title += "当前是否交易,";
            title += "持仓类型,";
            title += "持仓日期类型,";
            title += "多头保证金率,";
            title += "空头保证金率";

            qDebug() << QString::fromLocal8Bit(title);

            title += "\n";

            file.write(title);
        }

        QByteArray content;
        content += pInstrument->InstrumentID;
        content +=",";
        content += pInstrument->ExchangeID;
        content +=",";
        content += pInstrument->InstrumentName;
        content += ",";
        content += pInstrument->ExchangeInstID;
        content += ",";
        content += pInstrument->ProductID;
        content += ",";
        content += pInstrument->ProductClass;
        content += ",";
        content += QByteArray::number(pInstrument->DeliveryYear);
        content += ",";
        content += QByteArray::number(pInstrument->DeliveryMonth);
        content += ",";
        content += QByteArray::number(pInstrument->MaxMarketOrderVolume);
        content += ",";
        content += QByteArray::number(pInstrument->MinMarketOrderVolume);
        content += ",";
        content += QByteArray::number(pInstrument->MaxLimitOrderVolume);
        content += ",";
        content += QByteArray::number(pInstrument->MinLimitOrderVolume);
        content += ",";
        content += QByteArray::number(pInstrument->VolumeMultiple);
        content += ",";
        content += QByteArray::number(pInstrument->PriceTick);
        content += ",";
        content += pInstrument->CreateDate;
        content += ",";
        content += pInstrument->OpenDate;
        content += ",";
        content += pInstrument->ExpireDate;
        content += ",";
        content += pInstrument->StartDelivDate;
        content += ",";
        content += pInstrument->EndDelivDate;
        content += ",";
        content += pInstrument->InstLifePhase;
        content += ",";
        content += QByteArray::number(pInstrument->IsTrading);
        content += ",";
        content += pInstrument->PositionType;
        content += ",";
        content += pInstrument->PositionDateType;
        content += ",";
        content += QByteArray::number(pInstrument->LongMarginRatio);
        content += ",";
        content += QByteArray::number(pInstrument->ShortMarginRatio);

        qDebug() << QString::fromLocal8Bit(content);

        content += "\n";

        file.write(content);
    }

    file.close();
}

 


 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/6/27 21:51:42 [显示全部帖子]

        QDate startDate(2013,6,1);
        QDate endDate(2013,6,27);
        int b = startDate.daysTo(endDate);
        for(int i=0;i<=b;++i){
            CThostFtdcQrySettlementInfoField *req = new CThostFtdcQrySettlementInfoField();
            strcpy(req->TradingDay,startDate.addDays(i).toString("yyyyMMdd").toLocal8Bit().data());
            Commander *qry = new QrySettlementInfo(traderApi,req);
            commandQueue->enqueue(qry);
        }
[此贴子已经被作者于2013/6/27 21:52:07编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
z7c9
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
  发帖心情 Post By:2013/7/21 16:04:09 [显示全部帖子]

#include
#include
#include
#include
#include
#include

QString brokerId = "8070";
QString investorId = "888888";
QString password = "888888";
QString tradeFr;
QString quoteFr;

QStringList instrumentIds;

qint32 reqNo = 0;

CThostFtdcTraderApi *tradeApi = nullptr;
CThostFtdcMdApi *quoteApi = nullptr;

class QuoteSpi : public CThostFtdcMdSpi
{
public:
QuoteSpi()
{
quoteApi = CThostFtdcMdApi::CreateFtdcMdApi();
quoteApi->RegisterSpi(this);
quoteApi->RegisterFront(quoteFrontAddr.toLocal8Bit().data());
quoteApi->Init();
}

void OnFrontConnected()
{
CThostFtdcReqUserLoginField req;
memset(&req,0,sizeof(req));
quoteApi->ReqUserLogin(&req,++reqNo);
}

void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
qint32 size = instrumentIds.size();
char* *ppInstrumentId = new char*[size];
for(int i=0;i QByteArray ba = instrumentIds.at(i).toLocal8Bit();
ppInstrumentId[i] = new char[ba.size()];
strcpy(ppInstrumentId[i],ba.data());
}
quoteApi->SubscribeMarketData(ppInstrumentId,size);
delete [] ppInstrumentId;
ppInstrumentId = nullptr;
}

void OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData)
{
qDebug() << QString::fromLocal8Bit(pDepthMarketData->InstrumentID);
qDebug() << QString::number(pDepthMarketData->LastPrice);
}
};

class TradeSpi : public CThostFtdcTraderSpi
{
public:
TradeSpi()
{
tradeApi = CThostFtdcTraderApi::CreateFtdcTraderApi();
tradeApi->RegisterSpi(this);
tradeApi->SubscribePublicTopic(THOST_TERT_RESTART);
tradeApi->SubscribePrivateTopic(THOST_TERT_RESTART);
tradeApi->RegisterFront(tradeFrontAddr.toLocal8Bit().data());
tradeApi->Init();
}

void OnFrontConnected()
{
CThostFtdcReqUserLoginField req;
memset(&req,0,sizeof(req));
strcpy(req.BrokerID,brokerId.toLocal8Bit().data());
strcpy(req.UserID,investorId.toLocal8Bit().data());
strcpy(req.Password,password.toLocal8Bit().data());
tradeApi->ReqUserLogin(&req,++reqNo);
}

void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
CThostFtdcSettlementInfoConfirmField req;
memset(&req,0,sizeof(req));
tradeApi->ReqSettlementInfoConfirm(&req,++reqNo);
}

void OnRspSettlementInfoConfirm(CThostFtdcSettlementInfoConfirmField *pSettlementInfoConfirm, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
CThostFtdcQryInstrumentField req;
memset(&req,0,sizeof(req));
tradeApi->ReqQryInstrument(&req,++reqNo);
}

void OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
if(pInstrument){
instrumentIds.append(QString::fromLocal8Bit(pInstrument->InstrumentID));
}

if(bIsLast){
QuoteSpi *quoteSpi = new QuoteSpi();
}
}
};

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

TradeSpi *tradeSpi = new TradeSpi();

return a.exec();
}


[此贴子已经被作者于2013/7/21 16:04:46编辑过]

 回到顶部
总数 11 1 2 下一页