Qt使用workflow

  1. Qt工程设置

在这里插入图片描述

QMAKE_CFLAGS_DEBUG += -MTd
QMAKE_CXXFLAGS_DEBUG += -MTd

上述内容必须设置,否则会报错:error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”不匹配值“MDd_DynamicDebug。

在这里插入图片描述

libworkflow.pri的文件内容如下:
# 动态编译与静态编译不匹配
QMAKE_CFLAGS_DEBUG += -MTd
QMAKE_CXXFLAGS_DEBUG += -MTd

# OpenSSL库
INCLUDEPATH += $(OPENSSL_ROOT_DIR)/include
DEPENDPATH += $(OPENSSL_ROOT_DIR)/include
LIBS += -L$(OPENSSL_ROOT_DIR)/lib
LIBS += -llibcrypto -llibssl

# workflow
INCLUDEPATH += $$PWD/include
DEPENDPATH += $$PWD/include

CONFIG(debug, debug|release){
    LIBS += -L$$PWD/lib
    LIBS += -lworkflowd
}else{
    LIBS += -L$$PWD/lib
    LIBS += -lworkflow
}

LIBS += -lwsock32 -lws2_32

OpenSSL的配置查看上一篇文件:在Win10中使用VS2017编译workflow

  1. 使用workflow的WFHttpServer类实现一个HTTP服务器,浏览器访问时显示一个爱心界面

main.cpp

#include <iostream>
#include <fstream>
#include "workflow/WFHttpServer.h"

using namespace std;
using namespace protocol;

void http_callback(WFHttpTask *task)
{
    //读取Html文件
    ifstream ifs;
    ifs.open("web.html", ios::in);
    if(!ifs.is_open())
    {
        cout << "HTML文件打开失败" << endl;
        return;
    }

    //char content[1024 * 2] = { 0 };
    //while(!ifs.eof()){
    //    ifs.getline(content, 2048);
    //    cout << content << endl;
    //}
    //while(ifs >> content){
    //    cout << content << endl;
    //}

    std::string webStr;
    system("cls");
    std::string tmp;
    while(getline(ifs, tmp)){
        webStr += tmp;
        cout << tmp << endl;
    }
    ifs.close();

    cout << __FUNCTION__ << " " << __LINE__ << " " << webStr << endl;
    task->get_resp()->append_output_body(webStr);
}

int main()
{
    WFHttpServer server(http_callback);

    if (server.start(8888) == 0) {  // start server on port 8888
        getchar(); // press "Enter" to end.
        server.stop();
    }

    cout << "Hi Workflow" << endl;
    return 0;
}

web.html

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Main Content</title>
  <meta name="description" content="Main Content">
  <meta name="author" content="WILL">
</head>
<style>
.one{
  position:relative;
  width:100px;
  height:100px;
  background:pink;
  margin-left:100px;
  margin-top:100px;
  transform:rotate(-45deg);
}
.one:before{
  content:"";
  position:absolute;
  width:100px;
  height:100px;
  background-color:pink;
  border-radius:50%;
  top:-50px;
	left:0;
}
.one:after{
  content:"";
  position:absolute;
  background-color:pink;
  border-radius:50%;
  height:100px;
  width:100px;
  left:50px;
  top:0;
}
#content{
  position:absolute;
  top:20px;
  left:25px;
  z-index:2;
  font-size:15px;
  transform:rotate(45deg);
}
</style>
<body>
	<div class="one" >
    <span id="content">L O V E</span>
    </div>
</body>
</html>
  1. 浏览器访问 http://127.0.0.1:8888/

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晓琴儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值