QueryModel problem in container
Added by Samuele Pederzini over 3 years ago
Hi,
I have a problem if I use Querymodel inside a WTableView in a WContainerWidget goes into segmentation fault.
But if I'm inside WApplication the same code works perfectly.
IosDebugApplication::IosDebugApplication(const Wt::WEnvironment& env) : WApplication(env)
{
pBackend = new Wt::Dbo::backend::MySQL("namedb","username","password" , "localhost", 3306 );
session.setConnection(pBackend->clone());
session.mapClass<IosModule>("ios_module");
try
{
session.createTables();
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
}
auto table = Wt::cpp14::make_unique<Wt::WTableView>();
auto modelData = std::make_shared<Wt::Dbo::QueryModel<Wt::Dbo::ptr<IosModule>>>();
modelData->setQuery(session.query<Wt::Dbo::ptr<IosModule>>("select IosModule from ios_module IosModule "));
modelData->addAllFieldsAsColumns();
table->setColumnResizeEnabled(false);
table->setColumnAlignment(0, Wt::AlignmentFlag::Center);
table->setHeaderAlignment(0, Wt::AlignmentFlag::Center);
table->setAlternatingRowColors(true);
table->setRowHeight(28);
table->setHeaderHeight(28);
table->setSelectionMode(Wt::SelectionMode::Single);
table->setEditTriggers(Wt::EditTrigger::SingleClicked);
table->setColumnResizeEnabled(true);
table->setModel(modelData);
root()->addWidget(std::move(table));
In ContainerWidget not work:
MainContainer::MainContainer(Wt::Dbo::SqlConnectionPool& appDb) : Wt::WContainerWidget(), session(appDb)
{
Wt::Dbo::Transaction tramd{session};
auto table = Wt::cpp14::make_unique<Wt::WTableView>();
auto modelData = std::make_shared<Wt::Dbo::QueryModel<Wt::Dbo::ptr<IosModule>>>();
modelData->setQuery(session.query<Wt::Dbo::ptr<IosModule>>("select IosModule from ios_module IosModule "));
modelData->addAllFieldsAsColumns();
auto vb = setLayout(std::make_unique<Wt::WVBoxLayout>());
auto ct = vb->addWidget(std::make_unique<Wt::WContainerWidget>());
ct->setOverflow(Wt::Overflow::Scroll);
table->setColumnResizeEnabled(false);
table->setColumnAlignment(0, AlignmentFlag::Center);
table->setHeaderAlignment(0, AlignmentFlag::Center);
table->setAlternatingRowColors(true);
table->setRowHeight(28);
table->setHeaderHeight(28);
table->setSelectionMode(SelectionMode::Single);
table->setEditTriggers(EditTrigger::SingleClicked);
table->setColumnResizeEnabled(true);
table->setModel(modelData);
ct->addWidget(std::move(table));
}
Replies (5)
RE: QueryModel problem in container - Added by Korneel Dumon over 3 years ago
Hi,
this should not be a problem. Do you have a stacktrace for the crash?
RE: QueryModel problem in container - Added by Samuele Pederzini over 3 years ago
This is the only thing i get in the output
2021-May-04 10:23:02.976] 15319 - [info] "config: reading Wt config file: /etc/wt/wt_config.xml (location = './ios_debug_core.wt')"
[2021-May-04 10:23:02.977] 15319 - [info] "WServer/wthttp: initializing built-in wthttpd"
[2021-May-04 10:23:02.977] 15319 - [info] "wthttp: started server: http://0.0.0.0:8080"
[2021-May-04 10:23:04.619] 15319 - [info] "Wt: session created (#sessions = 1)"
[2021-May-04 10:23:04.620] 15319 [/ jjfW1IFFXpnptMjZ] [info] "WEnvironment: UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.51"
192.168.30.43 - - [2021-May-04 10:23:04.621] "GET / HTTP/1.1" 200 2285
[2021-May-04 10:23:04.621] 15319 - [info] "WebRequest: took 2.114 ms"
Dbo.backend.MySQL: SET sql_mode='ANSI_QUOTES,REAL_AS_FLOAT'
Dbo.backend.MySQL: SET default_storage_engine=INNODB;
Dbo.backend.MySQL: SET NAMES 'utf8mb4';
Dbo.backend.MySQL: SET sql_mode='ANSI_QUOTES,REAL_AS_FLOAT'
Dbo.backend.MySQL: SET default_storage_engine=INNODB;
Dbo.backend.MySQL: SET NAMES 'utf8mb4';
Dbo.backend.MySQL: SET sql_mode='ANSI_QUOTES,REAL_AS_FLOAT'
Dbo.backend.MySQL: SET default_storage_engine=INNODB;
Dbo.backend.MySQL: SET NAMES 'utf8mb4';
Dbo.backend.MySQL: SET sql_mode='ANSI_QUOTES,REAL_AS_FLOAT'
Dbo.backend.MySQL: SET default_storage_engine=INNODB;
Dbo.backend.MySQL: SET NAMES 'utf8mb4';
Dbo.backend.MySQL: SET sql_mode='ANSI_QUOTES,REAL_AS_FLOAT'
Dbo.backend.MySQL: SET default_storage_engine=INNODB;
Dbo.backend.MySQL: SET NAMES 'utf8mb4';
Dbo.backend.MySQL: start transaction
Dbo.backend.MySQL: create table "ios_container" (
"id" BIGINT primary key AUTO_INCREMENT,
"version" integer not null,
"name" text not null,
"type" integer not null
)
Dbo.backend.MySQL: rollback
MySQL error performing query: 'create table "ios_container" (
"id" BIGINT primary key AUTO_INCREMENT,
"version" integer not null,
"name" text not null,
"type" integer not null
)': Table 'ios_container' already exists
Using existing database192.168.30.43 - - [2021-May-04 10:23:04.888] "GET /?wtd=jjfW1IFFXpnptMjZ&request=style&page=1 HTTP/1.1" 200 92
[2021-May-04 10:23:04.888] 15319 - [info] "WebRequest: took 257.626 ms"
Segmentation fault (core dumped)
this is a class
#include <Wt/Dbo/Dbo.h>
#include "dboEnums.h"
namespace dbo = Wt::Dbo;
class IosModule
{
public:
IosModule(){};
~IosModule(){};
TypeModule type;
std::string name;
std::string uri;
std::string user;
std::string password;
int port;
std::string specificName;
std::string queryResources;
template<class Action>
void persist(Action& a)
{
dbo::field(a, type, "type");
dbo::field(a, name, "name");
dbo::field(a, specificName, "specific_name");
dbo::field(a, uri, "uri");
dbo::field(a, user, "user");
dbo::field(a, password, "password");
dbo::field(a, port, "port");
dbo::field(a, queryResources, "query_resources");
}
};
When i comment table->setModel(modelData); or ct->addWidget(std::move(table)); the program works perfectly.
RE: QueryModel problem in container - Added by Korneel Dumon over 3 years ago
Can you not run it in the debugger? Then it will break when the segfault happens and you can check the stacktrace.
RE: QueryModel problem in container - Added by Samuele Pederzini over 3 years ago
this is my debug stack
)
the debugger crashes here, in return connectionPool_->getConnection();
std::unique_ptr<SqlConnection> Session::useConnection()
{
if (connectionPool_)
return connectionPool_->getConnection();
else
return std::move(connection_);
}
[Solved]RE: QueryModel problem in container - Added by Samuele Pederzini over 3 years ago
OK I solved
I was wrong in the session reference