[Qt-interest] QStringListModel setStringList usage
Francisco Gonzalez
gzmorell at gmail.com
Wed Dec 22 10:02:56 CET 2010
Hello,
I am trying to use QStringListModel, and setting the content with
setStringList, but this function seems not to set the QStringListModel
data, or I am not understanding what is the purpose of the function.
Here is a little example.
During the Test object creation it seems to work as intended. But when
I call the check method it do not.
The output of the program is:
3
("One", "Two", "Three") --> During
-1806992878
()
Should the internal data of the QStringListModel being set with other
method? i.e. setData(), but then Why it works during initialization?
And what is the purpose of setStringList?
regards,
Francisco Gonzalez
--------------------------------------------------------------------------------
source
#include <QCoreApplication>
#include <QStringListModel>
#include <QDebug>
class Test
{
private:
QStringListModel *myModel;
QStringList myList;
public:
void check()
{
qDebug() << myModel->stringList().size();
qDebug() << myModel->stringList();
};
public:
Test()
{
myList << "One" << "Two" << "Three" ;
QStringListModel *myModel = new QStringListModel();
myModel->setStringList(myList);
qDebug() << myModel->stringList().size();
qDebug() << myModel->stringList();
};
~Test()
{
};
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Test t;
t.check();
return 0;
}
More information about the Qt-interest-old
mailing list