Setting qml's property
-
@
QObject oggettoContenuto = view->rootObject()->findChild<QObject>("testoContenuto");
if(oggettoContenuto) oggettoContenuto->setProperty("text", QVariant::fromValue(this->makeListnotes().at(index)))
@@
Flickable {
id: flickable1
x: 0
y: 0
width: 360
height: 640Text { id: text2 objectName: "testoTitolo" x: 30 y: 74 width: 295 height: 459 clip: true smooth: true font.pixelSize: 12 } Text { id: text1 objectName: "testoContenuto" x: 30 y: 32 width: 295 height: 21 smooth: true font.pixelSize: 12 } }
@
@
QList<Nota> Gestore::makeListnotes()
{
/*
formato:
[titolo]\n
[contenuto] ENDN\n\n
*/
QDir dir("C:/CreateANote");
QList<Nota> listnotes;
if(dir.exists())
{
QFile file("C:/CreateANote/listanote.txt");
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
int i = 0;
QTextStream streami(&file);
streami.seek(0);
while(!streami.atEnd())
{
listnotes.append(Nota(streami.readLine(), streami.readLine()));
qDebug() << listnotes.at(i).tostring();
streami.readLine();
streami.read(1);
streami.flush();
i++;
}
}
}
else
{
listnotes.append(Nota("Nessuna nota trovata", "Crea una nuova nota!"));
}
return listnotes;
}
@why this code returns this error (this is not the first time) with the first snippet?
@
In file included from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtGui/qgraphicsview.h:45,
from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtDeclarative/qdeclarativeview.h:48,
from c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtDeclarative/QDeclarativeView:1,
from ..\createANote\gestore.cpp:2:
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtCore/qmetatype.h: In static member function 'static int QMetaTypeId2<T>::qt_metatype_id() [with T = Nota]':
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtCore/qmetatype.h:230: instantiated from 'int qMetaTypeId(T*) [with T = Nota]'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtCore/qvariant.h:457: instantiated from 'QVariant qVariantFromValue(const T&) [with T = Nota]'
c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtCore/qvariant.h:340: instantiated from 'static QVariant QVariant::fromValue(const T&) [with T = Nota]'
..\createANote\gestore.cpp:85: instantiated from here
@ -
You have to register Nota as a QVariant type, see "this thread":http://developer.qt.nokia.com/forums/viewthread/6738 . You should use "Q_DECLARE_METATYPE()":http://doc.qt.nokia.com/4.7/qmetatype.html#Q_DECLARE_METATYPE and "qRegisterMetaType()":http://doc.qt.nokia.com/4.7/qmetatype.html#qRegisterMetaType