Project

General

Profile

Wt 4.0.3 QueryModel and WTableView question

Added by Pony Dazzler almost 6 years ago

Hello,

I am new to c and Wt but have been able to work through many of the examples and even created some of my own basic applications using code snippets from the wt examples.

The issue that I am having is that I cannot get the wt::dbo::QueryModel to work with WTableView. I am using wt 4.0.3. where setting the model on tableview has changed from Wt 3.3.10

#include <Wt/WTableView.h>

void Wt::WTableView::setModel (const std::shared_ptr< WAbstractItemModel > & model )

I was able to create an example using both WStandardItemModel and WStringListModel and both worked without issue. But when I tried to expand on the examples by connecting to MySql, things do not go so well.

// Using Wt::Dbo::QueryModel

auto dUser1 = std::make_shared<Wt::Dbo::QueryModel<Wt::Dbo::ptr>>();

dUser1->setQuery(session.find());

dUser1->addAllFieldsAsColumns();

// I validated that dUser1 is connecting to db and executing query by sending results to std::cerr

const auto dUser1 = std::make_shared<Wt::Dbo::QueryModel<Wt::Dbo::ptr>>();

dUser1->setQuery(session.find());

dUser1->addAllFieldsAsColumns();

for (int row = 0; row < dUser1->rowCount(); ++row) {

for (int column = 0; column < dUser1->columnCount(); ++column) {

auto aItem = std::make_uniqueWt::WStandardItem();

aItem->setText("Item " + std::to_string(row)

  • ", " + std::to_string(column));
    aModel->setItem(row, column, std::move(aItem));
    }
    }

//Finally, I added the tableview set some of the attributes and applied the model;

auto tv = root()->addWidget(Wt::cpp14::make_uniqueWt::WTableView());

tv->setAlternatingRowColors(false);

tv->setColumnResizeEnabled(false);

tv->setSelectionMode(SelectionMode::Single);

//The failure occurs whenever I try to apply the query model to the tableview;

tv->setModel(dUser1); // This causes the page/server to crash !!!

The code compiles, but the server crashes whenever I hit the webpage. What I mean by crash is that I get a core dump. Any help would be appreciated.

Thanks!

PD


Replies (3)

RE: Wt 4.0.3 QueryModel and WTableView question - Added by lm at almost 6 years ago

Welcome to C and Wt. What were you using before this?

If you're getting a segmentation fault, it's likely a problem with how you connected everything up. Run in a debugger: gdb --args ./myapp --docroot blah blah blah, then when the segmentation fault happens, type "bt" then enter into gdb and see what the stack trace is. (Be sure you compile with -g -O0 for the most useful output from gdb.)

RE: Wt 4.0.3 QueryModel and WTableView question - Added by Pony Dazzler almost 6 years ago

Thanks for the response.

I am not a programmer by profession (anymore) just more of a hobbyist. In the late 90s I was programming barcode readers using C. I came across Wt recently and became interested in writing web apps using c. Most of the programming concepts are pretty straight forward, but there are several of features that I am still wrapping my head around.

Anyway thanks for the suggestion. I will check it out this evening.

pd

RE: Wt 4.0.3 QueryModel and WTableView question - Added by Ansal P.A. over 5 years ago

Avoid the for loop and try to fetch actual data from database

Read the below answer to avoid a specific type of debug error

https://redmine.emweb.be/boards/1/topics/15622

    (1-3/3)