首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wt数据库Wt::Dbo

Wt数据库Wt::Dbo
EN

Stack Overflow用户
提问于 2014-10-17 07:35:39
回答 2查看 1.5K关注 0票数 3

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

我一开始就被困住了。我正在尝试从dbo教程(网站tt中有一个教程)学习它,这是Wt包中的示例(教程1.C)。

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

找不到lGL collect2: ld返回1个退出状态

下面是Wt中的代码(直接从教程1.C复制)

代码语言:javascript
复制
/*
 * 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();
}

提前感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-17 07:55:20

这个问题似乎是由于.pro文件而发生的。我不知道它是如何工作的,但当我第一次实现pro文件时,问题就消失了(从另一个.pro文件复制粘贴,修改很少,第一个文件,最后一个文件之间不应该有任何区别)。

票数 2
EN

Stack Overflow用户

发布于 2018-01-17 09:55:46

首先,您需要了解Qt不是编译器。它是一个开发跨平台应用程序和GUI的框架。我相信,您也可以使用,这是一个IDE。实际的编译器可能是gcc,clang,msvc或其他。链接错误指示您正在将其构建为gui应用程序。在pro文件中添加“CONFIG -= qt”将解决这个问题。或者,在创建新项目时选择非Qt项目->平原C++应用程序。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26420136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档