如何利用QTcreator 開發Wt(C++ web toolkit)程式

來源:互聯網
上載者:User

Wt是什嗎? 我不想做過的解釋,如果感興趣的朋友可以去http://www.webtoolkit.eu/wt看一看,wt是將來嵌入式開發的一種必然趨勢,因為wt現在剛剛起步,還沒有相對成熟的,設定連自己的一套開發jdk還沒有出來,這給開發wt的人員帶來了相當大的痛苦,本人也是配置wt的開發環境花了四天的時間,最後放棄了wt官方的資料(實在不敢恭維wt的官方資料),利用qtcreator來開發wt。

 

從一個簡單的helloword開始吧 

pro檔案

 

#-------------------------------------------------

#

# Project created by QtCreator 2010-11-18T12:10:20

#

#-------------------------------------------------

QT       -= core

QT       -= gui

TARGET = hello.wt

LIBS += -L/usr/local/lib -lwt -lwthttp

CONFIG   += console

CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

main.cpp#include <Wt/WApplication>#include <Wt/WBreak>#include <Wt/WContainerWidget>#include <Wt/WLineEdit>#include <Wt/WPushButton>#include <Wt/WText>#include <boost/version.hpp>using namespace Wt;/** A simple hello world application class which demonstrates how to react* to events, read input, and give feed-back.*/class HelloApplication : public WApplication{public:  HelloApplication(const WEnvironment& env);private:  WLineEdit *nameEdit_;  WText *greeting_;  void greet();};/** The env argument contains information about the new session, and* the initial request. It must be passed to the WApplication* constructor so it is typically also an argument for your custom* application constructor.*/HelloApplication::HelloApplication(const WEnvironment& env)  : WApplication(env){  setTitle("Hello");                               // application title  root()->addWidget(new WText("Your name, please ? "));  // show some text  nameEdit_ = new WLineEdit(root());                     // allow text input  nameEdit_->setFocus();                                 // give focus  WPushButton *b = new WPushButton("Greet me.", root()); // create a button  b->setMargin(5, Left);                                 // add 5 pixels margin  root()->addWidget(new WBreak());                       // insert a line break  greeting_ = new WText(root());                         // empty text  /*   * Connect signals with slots   *   * - simple Wt-way   */  b->clicked().connect(this, &HelloApplication::greet);  /*   * - using an arbitrary function object (binding values with boost::bind())   */  nameEdit_->enterPressed().connect    (boost::bind(&HelloApplication::greet, this));}void HelloApplication::greet(){  /*   * Update the text, using text input into the nameEdit_ field.   */  greeting_->setText("Hello there, " + nameEdit_->text());}WApplication *createApplication(const WEnvironment& env){  /*   * You could read information from the environment to decide whether   * the user has permission to start a new application   */  return new HelloApplication(env);}int main(int argc, char **argv){  /*   * Your main method may set up some shared resources, but should then   * start the server application (FastCGI or httpd) that starts listening   * for requests, and handles all of the application life cycles.   *   * The last argument to WRun specifies the function that will instantiate   * new application objects. That function is executed when a new user surfs   * to the Wt application, and after the library has negotiated browser   * support. The function should return a newly instantiated application   * object.   */  return WRun(argc, argv, &createApplication);}這就是helloword 的工程檔案現在編譯肯定是無法啟動並執行然後在運行環境中添加wt的共用庫地址 好了 現在開啟瀏覽器 輸入0.0.0.0:8080 點擊編譯運行 成功 ,這樣開發起來效率不知道高出n倍吧,誒,不知道wt 什麼時候才能在國內普及呢 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.