Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Einstieg in Model-View-Konzept
Forum Updated to NodeBB v4.3 + New Features

Einstieg in Model-View-Konzept

Scheduled Pinned Locked Moved German
109 Posts 10 Posters 103.2k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    thorben
    wrote on last edited by
    #95

    Ok dann habe ich wohl sowas wie einen "Copy-Paste"-Fehler. Denn wenn ich z. B. das StringListModel aus dem Assistant verwende, funktioniert das auch. Gibt es einen Part (aus deiner Erfahrung) den man bei MV-Prog. gerne vergisst oder Fehler einbaut? Btw. unter welchen Umständen wird die data()-Methode nicht aufgerufen.

    It's time to ... whatever

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

      Poste mal deinen model code, dann ist es vermuitlich leicht zu finden.
      data wird z.b. nicht aufgerufen, wenn rowCounf oder columnCount 0 liefern

      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
      • T Offline
        T Offline
        thorben
        wrote on last edited by
        #97

        Hier noch cdmodel.cpp

        <code>
        #include <QtGui/QMessageBox>
        //lokale "includes"
        #include "cdmodel.h"

        CdModel::CdModel(CdRack& data, QObject* parent) : QAbstractItemModel(parent), m_data(data)
        {
        connect(&m_data, SIGNAL(reset()), this, SLOT(reloead()));
        connect(&m_data, SIGNAL(inserted(int)), this, SLOT(inserted(int)));
        connect(&m_data, SIGNAL(inserted(int, int)), this, SLOT(inserted(int, int)));

        m_columns.append(tr("Title"));
        m_columns.append(tr("Author"));
        m_columns.append(tr("Genre"));
        m_columns.append(tr("Year"));
        }
        QModelIndex CdModel::index(int row, int column, const QModelIndex &parent) const
        {
        //if(!parent.isValid())
        if(parent.isValid()) //Evtl. muss hier negiert werden
        {
        return QModelIndex();
        }

        if((0 <= row) && (row < rowCount()) &&
        (0 <= column) && (column < columnCount()))
        {
        return createIndex(row, column); //Index für Zugriff von außen erstellen
        }
        return QModelIndex();
        }
        QModelIndex CdModel::parent(const QModelIndex &child) const
        {
        return QModelIndex();
        }

        int CdModel::rowCount(const QModelIndex &parent) const
        {
        //QMessageBox::information(0, tr(""), tr("in CdModel::rowCount"));
        return m_data.size();
        }
        int CdModel::columnCount(const QModelIndex &parent) const
        {

        //QMessageBox::information(0, tr(""), tr("in CdModel::columnCount"));
        //if(!parent.isValid())
        if(parent.isValid()) //Evtl. muss das negiert werden ?????
        {
        return 0;
        }
        return m_columns.count();
        }
        QVariant CdModel::data(const QModelIndex &index, int role) const
        {
        QMessageBox::information(0, tr(""), tr("in CdModel::data()"));
        if(!index.isValid())
        {
        return QVariant();
        }
        if(Qt::DisplayRole == role)
        {
        const CdDisk& rDisk = m_data.at(index.row());
        switch(index.column())
        {
        case 0:
        return rDisk.m_title;
        break;
        case 1:
        return rDisk.m_author;
        break;
        case 2:
        return rDisk.m_genre;
        break;
        case 3:
        return rDisk.m_year;
        break;
        }
        }
        return QVariant();
        }
        QVariant CdModel::headerData(int section, Qt::Orientation orientation, int role) const
        {
        if( (Qt::DisplayRole == role) && (Qt::Horizontal == orientation) &&
        (0 <= section) && (section < columnCount()))
        {
        return m_columns.at(section);
        }
        return QVariant();
        }

        void CdModel::reload()
        {
        reset();
        }
        void CdModel::inserted(int nPosition)
        {
        //TODO
        }
        void CdModel::inserted(int nFirst, int nLast)
        {
        //TODO
        }
        </code>

        It's time to ... whatever

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

          Benutz bitte mal das original beispiel projekt und teste, ob das bei dir geht.
          Evtl hast du im header auch irgendwo ein const zuviel / zuwenig etc...

          Spontan sehe ich keinen fehler. Oder du postest mal deinen gesamten code via pastebin oder so gitorious oder so

          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
          • T Offline
            T Offline
            thorben
            wrote on last edited by
            #99

            ORiginal-Projekt geht!
            Habe bei mir nochmal gesucht und den Fehler gefunden:
            -> rowCount() lieferte 0
            Evtl. wg. dieser Zeile:
            <code>
            connect(&m_data, SIGNAL(reset()), this, SLOT(reloead()));
            </code>

            Habe aus reloead() ein reloead() gemacht und es ging!

            It's time to ... whatever

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thorben
              wrote on last edited by
              #100

              Ups,

              sollte reload() heißen

              It's time to ... whatever

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

                Puh, ich dachte schon, ich hätte vor dem zippen irgendwo noch einen bug eingebaut ... :-)

                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
                • T Offline
                  T Offline
                  thorben
                  wrote on last edited by
                  #102

                  Morgen,
                  in den bisherigen XML-Dateien befinden sich ja nur wenige Informationen.
                  Ich überlege mir, ob man z. B. über einen Doppelklick auf einen Eintrag nicht eine weitere XML-Datei öffnen könnte, die weitere Informationen enthält z. B. die komplette Titelliste einer CD oder so ....

                  It's time to ... whatever

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

                    Da kann man viel machen, auch eine CDDB anbindung wäre vorstellbar, aber um MVC zu zeigen langt es meiner Meinung nach :-)

                    Das mit den Titellisten hatte ich mir auch schon überlegt, so als Tree dann, mal sehen. In letzter Zeit kam (außer jetzt von dir) gar keine Rückmeldung mehr, von daher habe ich nicht mehr dran weitergemacht.

                    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
                    • T Offline
                      T Offline
                      thorben
                      wrote on last edited by
                      #104

                      Moin,

                      nun ja zum einen beschäftige ich mich im Beruf jetzt intensiver damit, zum anderen ist eine solche Applikation für die Verwaltung meiner eigenen CDs, DVDs oder sonstiges recht praktisch.

                      It's time to ... whatever

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

                        [quote author="thorben" date="1315374169"]... zum anderen ist eine solche Applikation für die Verwaltung meiner eigenen CDs, DVDs oder sonstiges recht praktisch.[/quote]

                        Hehe, deswegen dachte ich mir, das wäre ein gutes Beispiel :-)

                        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
                        • T Offline
                          T Offline
                          thorben
                          wrote on last edited by
                          #106

                          Das stimmt wohl :-)
                          Wahrscheinlich hat sowas jeder zu Hause, aber selber machen, macht manchmal mehr Spaß, wenn man weiß wie ... daher in der Tat ein gutes Beispiel!

                          It's time to ... whatever

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

                            Mal sehen, evtl baue ich das mal noch fertig aus, aber wenn dann erst mit der Zeit....

                            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
                            • G Offline
                              G Offline
                              Granjow
                              wrote on last edited by
                              #108

                              Danke fürs Tutorial! Das war echt hilfreich.

                              Ich habe hier ein sehr kurzes Beispielprojekt, das eigene Items über QAbstractItemDelegate::paint() zeichnet: http://granjow.net/uploads/temp/ModelViewTest.tar.bz2 Lässt sich das eventuell auch irgendwo verwenden?

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                deleted516
                                wrote on last edited by
                                #109

                                Hallo jungs und mädels, frohe Weihnachten!!
                                Ich beschäftige mich grad mit dem modell view konzept um eins meiner Projekte zu realisieren!
                                Ich hab euer Tutorial gefunden und wollte es durcharbeiten! Aber leider sind alle links zu den dateien und des tutorials tot. Könntet ihr das tutorial vllt wieder auffrischen?
                                Das wäre sehr hilfreich für mich!!
                                Liebe Grüße!!

                                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