Project

General

Profile

How to put SQL query result into WTableView?

Added by Gerard Verhaag about 4 years ago

Hi,

I'm struggling with trying to figure out how to put SQL table query results into an WTableView, but haven't succeeded yet!

My efforts to understand the Wt::WAbstractTableModel and how to use it in combination with SQL end up in problems.

For me grasping the concept behind the model and implementing it correctly pose serious issues.

I went through the documentation on the site, and even looked in the reference section, but that didn't help to better understand the concept, sorry!

Any hints would be very helpful!

Regards,

Gerard


Replies (2)

RE: How to put SQL query result into WTableView? - Added by Stefan Bn about 4 years ago

Gerard Verhaag wrote:

I'm struggling with trying to figure out how to put SQL table query results into an WTableView, but haven't succeeded yet!

I just copy a little code from my project.

First setup your QueryModel with the respective SQL query and link the results from the SELECT statement to the resulting columns that should be viewed in your TableView:

urlVariablesQueryModel = std::make_shared<Dbo::QueryModel<UrlVariable>>();
urlVariablesQueryModel->setQuery(dbSession->query<UrlVariable>("SELECT id, keyName, description FROM url_parameters"));

urlVariablesQueryModel->addColumn("id", "ID");
urlVariablesQueryModel->addColumn("keyName", WString::tr("VariableKey"));
urlVariablesQueryModel->addColumn("description", WString::tr("Description"));

urlVariablesQueryModel->reload();

Then setup your TableView and just assign your Query Model to it:

auto resultTableUp = std::make_unique<WTableView>();
resultTableUp->setModel(userListQueryModel);

RE: How to put SQL query result into WTableView? - Added by Gerard Verhaag about 4 years ago

Thanks for your response!

Well I've some problems grasping all this.

I think I have to quit right here; I've not enough know-how of C to make my first Wt project really work, sorry!

Regards,

Gerard

    (1-2/2)