Wt 数据库 Wt::Dbo

标签 wt

我正在尝试为一个项目学习 Wt,现在我正在尝试学习其中的数据库部分。

我卡在了开头。我正在尝试从 dbo 教程(网站 http://www.webtoolkit.eu/wt/doc/tutorial/dbo/tutorial.html#_installing_tt_wt_dbo_tt 中有一个教程)学习它,它位于 Wt 包 (tutorial1.C) 中的示例中

我在 ubuntu 中使用 Qt 编译器 (5.)。我已经按照网站教程(上面链接)中的说明构建了 Wt::Dbo 库。问题是它仍然给出一个错误;

cannot find lGL
collect2: ld returned 1 exit status

这里是Wt自带的代码(直接从tutorial1.C复制而来)

/*
 * Copyright (C) 2010 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

/*****
 * This file is part of the Wt::Dbo tutorial:
 * http://www.webtoolkit.eu/wt/doc/tutorial/dbo/tutorial.html
 *****/

#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/backend/Sqlite3>
#include <string>

namespace dbo = Wt::Dbo;

/*****
 * Dbo tutorial section 2. Mapping a single class
 *****/

class User {
public:
  enum Role {
    Visitor = 0,
    Admin = 1,
    Alien = 42
  };

  std::string name;
  std::string password;
  Role        role;
  int         karma;

  template<class Action>
  void persist(Action& a)
  {
    dbo::field(a, name,     "name");
    dbo::field(a, password, "password");
    dbo::field(a, role,     "role");
    dbo::field(a, karma,    "karma");
  }
};

void run()
{
  /*****
   * Dbo tutorial section 3. A first session
   *****/

  /*
   * Setup a session, would typically be done once at application startup.
   *
   * For testing, we'll be using Sqlite3's special :memory: database. You
   * can replace this with an actual filename for actual persistence.
   */
  dbo::backend::Sqlite3 sqlite3(":memory:");
  sqlite3.setProperty("show-queries", "true");
  dbo::Session session;
  session.setConnection(sqlite3);

  session.mapClass<User>("user");

  /*
   * Try to create the schema (will fail if already exists).
   */
  session.createTables();

  {
    dbo::Transaction transaction(session);

    User *user = new User();
    user->name = "Joe";
    user->password = "Secret";
    user->role = User::Visitor;
    user->karma = 13;

    dbo::ptr<User> userPtr = session.add(user);
  }

  /*****
   * Dbo tutorial section 4. Querying objects
   *****/

  {
    dbo::Transaction transaction(session);

    dbo::ptr<User> joe = session.find<User>().where("name = ?").bind("Joe");

    std::cerr << "Joe has karma: " << joe->karma << std::endl;

    dbo::ptr<User> joe2 = session.query< dbo::ptr<User> >
      ("select u from user u").where("name = ?").bind("Joe");
  }

  {
    dbo::Transaction transaction(session);

    typedef dbo::collection< dbo::ptr<User> > Users;

    Users users = session.find<User>();

    std::cerr << "We have " << users.size() << " users:" << std::endl;

    for (Users::const_iterator i = users.begin(); i != users.end(); ++i)
      std::cerr << " user " << (*i)->name
        << " with karma of " << (*i)->karma << std::endl;
  }

  /*****
   * Dbo tutorial section 5. Updating objects
   *****/

  {
    dbo::Transaction transaction(session);

    dbo::ptr<User> joe = session.find<User>().where("name = ?").bind("Joe");

    joe.modify()->karma++;
    joe.modify()->password = "public";
  }

  {
    dbo::Transaction transaction(session);
    dbo::ptr<User> joe = session.find<User>().where("name = ?").bind("Joe");
    if (joe)
      joe.remove();
  }

  {
    dbo::Transaction transaction(session);

    dbo::ptr<User> silly = session.add(new User());
    silly.modify()->name = "Silly";
    silly.remove();
  }

}

int main(int argc, char **argv)
{
  run();
}

提前致谢

最佳答案

问题似乎是由 .pro 文件引起的。我不确定它是如何工作的,但是当我第一次实现它时替换 pro 文件时问题就消失了(从另一个 .pro 文件复制粘贴,修改很少,第一个和最后一个之间应该没有任何区别一)。

关于Wt 数据库 Wt::Dbo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26420136/

相关文章:

wsl-2 - 如何在WSL中安装和使用Wt(web GUI库)

c++ - 使用Wt C++时找不到Postgres header

C++,链接时出错。用 scons 构建

javascript - 在 WT 中嵌入 Ventus

c++ - Wt 从 http 响应回调添加新的小部件

c++ - std::bind 函数中没有可行的重载 '='

javascript - WT 能否将网页呈现为主页的一部分?

javascript - 使用 WT(Witty) 的 Javascript 函数。

c++ - 从其他网页调用 c++ web 工具包小部件?

c++ - 与/bigobj 链接时间过长