Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Setting qml's property
QtWS25 Last Chance

Setting qml's property

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    @
    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: 640

        Text {
            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
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved