Hi,

You have to use "setModelColumn"

videoCombo.setModelColumn(0);
videoCombo.setModel(model);

On 08/04/2014 03:26 ص, Jeffrey Scott Flesher Gmail wrote:
Does anyone have a working example of how to use QueryModel to bind to WComboBox or another like type of widget?
I could not find any examples and my guess below is not working.

I am trying to bind a single table with one column

class TheVideo
{
    public:
        TheVideo();
        std::string categories;   // categories for Combo box
        std::string name;         // Name for Combo box
        template<class Action>
        void persist(Action &a)
        {
            Wt::Dbo::field(a, categories,   "categories");
            Wt::Dbo::field(a, name,         "name");
        }
};
// My class is derived from Wt::Dbo::Session, I read from an XML file and correctly populate the table in this class
Wt::Dbo::QueryModel< Wt::Dbo::ptr<TheVideo> > *model = new Wt::Dbo::QueryModel< Wt::Dbo::ptr<TheVideo> >();
model->setQuery(query< Wt::Dbo::ptr<TheVideo> >("select u from video u").where("categories = ?").bind("IAM"), false);
model->addColumn("name");
videoCombo.setModel(model);

I have several rows in the table with the categories = IAM, but inspecting the model, currentRow_ = -1, I get a segment fault on setModel.

Thanks

On Thu, 2014-03-13 at 08:27 -0700, Jason H wrote:
Why wouldn't you just use a QSql[Query|Table]Model for the combo box?
Or in Wt, a Wt::Dbo::QueryModel< Result >

QXmlStreamReader is easy if the schema is easy. You just get elements as they occur.




________________________________
From: Jeffrey Scott Flesher Gmail <jeffrey.scott.fles...@gmail.com>
To: Wt <witty-interest@lists.sourceforge.net> 
Sent: Tuesday, March 11, 2014 7:23 PM
Subject: [Wt-interest] Can you use XML or SQL as a data source for WComboBox?



I do not see any examples of it, beside one very confusing forum thread, with no full example code, I did not find anything else, I am mostly interested in XML.

My guess would be that I would use:

combo = new WComboBox(this);
WStandardItemModel *si = new WStandardItemModel();

and use QXmlStreamReader to read in the data, and attach it with:

WStandardItem *i = new WStandardItem();
i->setData(p1.key, UserRole);
i->setText(p1.name);
si->appendRow(i);

combo->setModel(si);

Found this at http://andres.jaimes.net/799/how-to-use-a-combobox-with-cwt-witty/ 

I can work on this and get it to work with no problem, but I was wondering if there is an easier way, or if this is the way to do it.

Do you have a Wt class to read XML? 
or is QXmlStreamReader just as easy and fast?

Thanks 
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest


------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees


_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to