I tried to deal with WebToolkit and write my application by examples. But after starting work with the base, the problems started and the last and not solved by me is a memory leak after transferring the model to the view and view of the table of elements.
manTable = new Wt::WTable(); database *wsedb = new database(); wsedb->dbInit(); ... manView = new Wt::WTableView(); manView->setModel(wsedb->manModel); manTable->elementAt(1,0)->addWidget(manView);
I can not understand how to solve this problem, at all. It seems that the types are declared correctly, all the headers are connected, in the examples of developers the work goes the same. Sorts: database.h:
#ifndef DATABASE_H #define DATABASE_H #include<Wt/Dbo/backend/Sqlite3> #include<Wt/Dbo/Dbo> #include <Wt/Dbo/Session> #include <Wt/Dbo/QueryModel> #include <Wt/WApplication> #include "manuals.h"//map clases namespace dbo = Wt::Dbo; class database { public: database(); dbo::Session SessionW; dbo::QueryModel<dbo::ptr<manuals>> *manModel; void dbInit(); void dbTrans(); void addMan(); }; #endif // DATABASE_H
database.cpp:
#include "database.h" using namespace Wt; database::database() { } void database::dbInit() { dbo::backend::Sqlite3 wseDB=WApplication::instance()->appRoot() + "wse.db"; SessionW.setConnection(wseDB); wseDB.setProperty("show-queries", "true"); SessionW.mapClass<manuals>("manuals"); manModel=new dbo::QueryModel<dbo::ptr<manuals>>(); dbo::Transaction trans(SessionW); try{ SessionW.createTables(); Wt::log("info") << "Database created"; } catch (...) { Wt::log("info") << "Using existing database"; } trans.commit(); manModel->setQuery(SessionW.find<manuals>()); manModel->addAllFieldsAsColumns(); dbo::Transaction trans1(SessionW); Wt::Dbo::collection<Wt::Dbo::ptr<manuals> > a=SessionW.find<manuals>().orderBy("date desc"); trans1.commit(); }
manModel
indatabase
destructor. And whymanModel
in the heap, and not on the stack? - Cerbonew
operator. Put breakpoints there, go, look. Find, referring to which pointer causes an error. Then you figure out where you are changing this pointer. Well, Cerbo correctly noted that it is more logical to create an object on the stack. Or use smart pointers. - user1056837