Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Error: 'qt_metatype_id' is not a member of 'QMetaTypeId<Nota>'

    QML and Qt Quick
    2
    2
    4141
    Loading More Posts
    • 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
      spode last edited by

      @
      #ifndef GESTORE_H
      #define GESTORE_H

      #include <QObject>
      #include <QStringList>
      #include "nota.h"

      class Gestore : public QObject
      {
      Q_OBJECT

      public:
      explicit Gestore(QObject *parent = 0);

      private:
      void visualizzamainwindow();
      QList<Nota> makeListnotes();
      QStringList makeTitleslist();

      signals:
      
      public slots:
      void visualizzaNotaAt(int index);
      

      };

      #endif // GESTORE_H
      @

      @
      #include "gestore.h"
      #include <QDeclarativeView>
      #include <QDeclarativeContext>
      #include <QGraphicsObject>
      #include <QDir>
      #include <QTextStream>

      Gestore::Gestore(QObject *parent) :
      QObject(parent)
      {
      this->visualizzamainwindow();
      }

      void Gestore::visualizzamainwindow()
      {
      QDeclarativeView *view = new QDeclarativeView;
      view->rootContext()->setContextProperty("listaTitoli", QVariant::fromValue(this->makeTitleslist()));
      view->setSource(QUrl::fromLocalFile("qml/createANote/main.qml"));
      view->show();

      QObject *boj = view->rootObject();
      QObject::connect(boj, SIGNAL(signal_visualizzaNotaAt(int)), this, SLOT(visualizzaNotaAt(int)));
      

      }

      QStringList Gestore::makeTitleslist()
      {
      QList<Nota> listnotes = this->makeListnotes();
      QStringList titleslist;
      int i = 0;
      while(i < listnotes.count())
      {
      titleslist.append(listnotes[i].getTitolo());
      i++;
      }
      return titleslist;
      }

      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))
      {
      QTextStream streami(&file);
      while(!streami.atEnd())
      {
      listnotes.append(Nota(streami.readLine(), streami.readLine()));
      qDebug("sono");
      }
      }
      }
      else
      {
      listnotes.append(Nota("Nessuna nota trovata", "Crea una nuova nota!"));
      qDebug("qui");
      }
      return listnotes;
      }

      void Gestore::visualizzaNotaAt(int index)//this is what does not start with...see under
      {
      QDeclarativeView view;
      view.rootContext()->setContextProperty("titolo", QVariant::fromValue(this->makeTitleslist().at(index)));
      view.rootContext()->setContextProperty("contenuto", QVariant::fromValue(this->makeListnotes().at(index)));
      view.setSource(QUrl::fromLocalFile("qml/createANote/nota.qml"));
      view.show();
      }
      @

      @
      #ifndef NOTA_H
      #define NOTA_H

      #include <QString>

      class Nota
      {
      public:
      Nota();
      Nota(QString newtitolo, QString newcontenuto);

      void setTitolo(const QString newtitolo)
      {
          titolo = newtitolo;
      }
      
      void setContenuto(const QString newcontenuto)
      {
          contenuto = newcontenuto;
      }
      
      QString getContenuto()
      {
          return contenuto;
      }
      
      QString getTitolo()
      {
          return titolo;
      }
      

      private:
      QString contenuto;
      QString titolo;
      };

      #endif // NOTA_H
      @

      @
      #include "nota.h"

      Nota::Nota()
      {
      }

      Nota::Nota(QString newtitolo, QString newcontenuto) :
      titolo(newtitolo), contenuto(newcontenuto)
      {

      }
      @

      main.qml
      @
      import QtQuick 1.0

      Rectangle {
      width: 360
      height: 640
      gradient: Gradient {
      GradientStop {
      position: 0
      color: "#f3e302"
      }

          GradientStop {
              position: 0.500
              color: "#e2ac17"
          }
      
          GradientStop {
              position: 1
              color: "#d76363"
          }
      }
      
      Image {
          id: image1
          x: 26
          y: 526
          width: 309
          height: 73
          smooth: true
          source: "pulsante_arancione.png"
      
          Text {
              id: text1
              x: 106
              y: 0
              width: 98
              height: 48
              text: qsTr("Crea una nota")
              smooth: true
              anchors.verticalCenterOffset: -13
              anchors.horizontalCenterOffset: 0
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.verticalCenter: parent.verticalCenter
              z: 1
              font.family: "Aquiline"
              font.pixelSize: 21
          }
      }
      
      signal signal_visualizzaNotaAt(int index);
      ListView {
          id: list_view1
          x: 26
          y: 30
          width: 309
          height: 462
          spacing: 5
          delegate:
              Column
              {
                  spacing: 5; y: 15
                  Rectangle { width: 300; height: 40; color: "transparent"; Text { anchors.centerIn: parent; text: modelData } MouseArea { anchors.fill: parent; onClicked: signal_visualizzaNotaAt(index) } }
                  Rectangle { width: 300; height: 1; id: lineaDiSeparazione; color: "black" }
              }
          model: listaTitoli
      }
      

      }
      @

      nota.qml. this is what does not start
      @
      import QtQuick 1.0

      Rectangle {
      width: 360
      height: 640
      gradient: Gradient {
      GradientStop {
      position: 0
      color: "#3fc20f"
      }

          GradientStop {
              position: 0.460
              color: "#0ddd1e"
          }
      
          GradientStop {
              position: 1
              color: "#1aff72"
          }
      }
      
      property string titolo: "default title"
      property string contenuto: "default content"
      
      Flickable {
          id: flickable1
          x: 0
          y: 0
          width: 360
          height: 640
      
          Text {
              id: text2
              x: 30
              y: 74
              width: 295
              height: 459
              text: titolo
              clip: true
              smooth: true
              font.pixelSize: 12
          }
      
          Text {
              id: text1
              x: 30
              y: 32
              width: 295
              height: 21
              text: contenuto
              smooth: true
              font.pixelSize: 12
          }
      }
      

      }
      @

      1 Reply Last reply Reply Quote 0
      • K
        koahnig last edited by

        Looks like you have to register Nota "QMetaType":http://developer.qt.nokia.com/doc/qt-4.7/qmetatype.html

        Edit: This you have to "use":http://doc.qt.nokia.com/4.7/qmetatype.html#qRegisterMetaType for registration of your own types.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply Reply Quote 0
        • First post
          Last post