从其他网页调用c++ web toolkit widget

Calling c++ web toolkit widget from other webpages?

本文关键字:web toolkit widget c++ 调用 其他 网页      更新时间:2023-10-16

我是Wt框架的新手,我只是想知道是否有可能从其他网页调用Wt自定义小部件。我的意思是,如果我做了一个Wt应用程序,别人可以把它作为api来使用其他框架来开发吗?或者我的应用程序将成为Wt专用的应用程序?

Wt有一个'widgetset'模式,在这种模式下,你可以在其他网站上显示你的Wt应用程序的小部件,类似于你如何将谷歌地图小部件添加到静态网站。

正如user52875's提到的,你需要告诉Wt你的应用是一个Wt::widgetSet。

下面是一个示例,修改自Wt的helloworld和主页示例:

#include <Wt/WServer>
#include <Wt/WText>
using namespace Wt;
class MyApp : public WApplication {
public:
    MyApp(const WEnvironment& env) : WApplication(env) {
        new WText("Hello", root());
    }
};
WApplication *createApplication(const WEnvironment& env)
{
  return new MyApp(env);
}
int main(int argc, char **argv)
{
  try {
    WServer server(argc, argv, WTHTTP_CONFIGURATION);
    // ********** Pass 'Wt::WidgetSet' instead of 'Wt::Application' here ************
    server.addEntryPoint(WidgetSet, createApplication, "/");
    server.run();
  } catch (Wt::WServer::Exception& e) {
    std::cerr << e.what() << std::endl;
  } catch (std::exception &e) {
    std::cerr << "exception: " << e.what() << std::endl;
  }
}