[solved] problems with qstringlist



  • @
    QList<Nota> Gestore::getAllNotes()
    {
    QDir dir("C:/CreateANote");
    QList<Nota> listaNote;
    if(dir.exists())
    {
    QFile file("C:/CreateANote/listnotes.txt");
    if(file.open(QIODevice::Text | QIODevice::ReadOnly))
    {
    bool done_withItitles = false;
    QTextStream streami(&file);
    int i = -1;
    while(!streami.atEnd())//finchè nn sei a fine documento
    {
    i++;
    done_withItitles = false;
    QString parola;
    while(!parola.contains("ENDNOTE\n")) //finchè la nota non è finita
    {
    listaNote.append(Nota());
    parola = streami.read(40);
    if(parola.contains("TI-"))
    {
    continue;
    }
    else if(parola.contains("TE-"))
    {
    done_withItitles = true;
    continue;
    }

                    if(done_withItitles)
                    {
                        listaNote[i].setContenuto(parola);
                    }
                    else
                    {
                        listaNote[i].setTitolo(parola);
                    }
                }
            }
        }
    }
    return listaNote;
    

    }

    /*

    formato:
    TI- [titolo] TE- [testo] ENDNOTE\n

    */

    QStringList Gestore::getAllNotes_title() //penso che questo sia inutile perchè potrei fare getTitolo
    {
    QDir dir("C:/CreateANote");
    QStringList listaTitles;
    if(dir.exists())
    {
    QList<Nota> listNote = this->getAllNotes();
    for(int i = 0; i <= listNote.count(); i++) //finchè la lista non è finita
    {
    listaTitles.append(listNote.at(i).getTitolo());
    }
    }
    return listaTitles;
    }
    @

    errors are:
    @
    debug\moc_gestore.cpp: In member function 'virtual int Gestore::qt_metacall(QMetaObject::Call, int, void**)':
    debug\moc_gestore.cpp:75: error: variable 'QStringList _r' has initializer but incomplete type
    debug\moc_gestore.cpp:75: error: invalid use of incomplete type 'struct QStringList'
    c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtCore/qstring.h:94: error: forward declaration of 'struct QStringList'
    mingw32-make[1]: *** [debug/moc_gestore.o] Error 1
    mingw32-make: *** [debug] Error 2
    The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    @

    with that functions i would to pass a qstringlist to qml listview in this way:
    @
    ListView {
    id: list_view1
    x: 14
    y: 144
    width: 332
    height: 369
    z: 1
    spacing: 5
    clip: true
    smooth: true
    delegate: Item {
    x: 5
    height: 40
    Row {
    id: row1
    spacing: 10
    Rectangle {
    width: 40
    height: 40

                    Text {
                        text: titolo
                        anchors.verticalCenter: parent.verticalCenter
                        font.bold: true
                    }
    
                    MouseArea {
                        anchors.fill: parent;
                        onClicked: gestore.visualizzaNotaAt(index)
                    }
                }
    
                Rectangle { id: line; width: 300; x: 10; height: 1; smooth: true }
            }
        }
        model: gestore.getAllNotes_title();
    }
    

    @

    p.s.: that functions are declared as q_invokable. i have already added q_obect macro.



  • Did you include QtCore/QStringList?



  • I imagine you have already qmlRegisterType<Gestore>.....
    Did you try the setContextProperty which is quite useful is many case?



  • @include <QStringList>@


  • Moderators

    [quote author="spode" date="1315473545"]@
    for(int i = 0; i <= listNote.count(); i++) //finchè la lista non è finita
    {
    listaTitles.append(listNote.at(i).getTitolo());
    }
    @ [/quote]

    Not an answer to your original post, but this part will crash in run time. You need change to"i < listNote.count()"
    @
    for(int i = 0; i < listNote.count(); i++) //finchè la lista non è finita
    {
    listaTitles.append(listNote.at(i).getTitolo());
    }
    @



  • so i changed the code as koahing said and included QStringList. the error is still there... =(



  • You have somewhere "class QStringList;". It usually reside in "...h" file, but could reside anywhere.

    It is "forward declaration". "#include <QStringList>" provides complete declaration.

    "class QStringList;" makes your compilation pass, but it results in incomplete class declaration without "#include <QStringList>".

    Option 1. Find "class QStringList;" and replace it with "#include <QStringList>".
    Option 2. Find "class QStringList;" in ...h file and put "#include <QStringList>" in corresponding ...cpp file.

    Before the row with the error there is another row with "in file..." which tells you in which ...cpp file you should add "#include <QStringList>".



  • this is the complete compile output of the app. i did not understand....
    @
    Running build steps for project createANote...
    Configuration unchanged, skipping qmake step.
    Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
    C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory C:/Users/7-Spode/Documents/Progetti/QT/mobile/createANote-build-desktop-Qt_4_7_3_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_DECLARATIVE_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtCore" -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtGui" -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtDeclarative" -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include" -I"..\createANote\qmlapplicationviewer" -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\include\ActiveQt" -I"debug" -I"..\createANote" -I"." -I"c:\QtSDK\Desktop\Qt\4.7.3\mingw\mkspecs\win32-g++" -o debug\moc_gestore.o debug\moc_gestore.cpp debug\moc_gestore.cpp: In member function 'virtual int Gestore::qt_metacall(QMetaObject::Call, int, void**)': debug\moc_gestore.cpp:75: error: variable 'QStringList _r' has initializer but incomplete type debug\moc_gestore.cpp:75: error: invalid use of incomplete type 'struct QStringList' c:\QtSDK\Desktop\Qt\4.7.3\mingw\include/QtCore/qstring.h:94: error: forward declaration of 'struct QStringList' mingw32-make[1]: Leaving directoryC:/Users/7-Spode/Documents/Progetti/QT/mobile/createANote-build-desktop-Qt_4_7_3_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug'
    mingw32-make[1]: *** [debug/moc_gestore.o] Error 1
    mingw32-make: *** [debug] Error 2
    The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project createANote (target: Desktop)
    When executing build step 'Make'
    @


  • Moderators

    Formand assumes that you have "tricked" the compiler somewhere in your code.
    You can simply declare class <classname> when you do not want to include the complete header file for some reason. E.g. this is handy when class A is is used in a parameter list of class B and the opposite.
    For example you can do:
    @
    class A;

    class B
    {
    public:
    .
    .
    .
    void foo ( A & a );
    .
    .
    .

    };

    class A
    {
    public:
    .
    .
    .
    void foo2 ( B & b );
    .
    .
    .

    };
    @

    You cannot declare completely class A before class B and vice versa. The single statement:
    @
    class A;
    @
    tells the compiler that "A" is a class, but you have to define it lateron. If you include this header file into the appropriate cpp-file and line out the appropriate methods in there, it should not give a compilation error.

    Formand assumes now that this has happened somewhere by accident in your own code for QStringList .
    The only way for you would be to check all source and header files involved to check for such an occurance of "class QStringList;" and substitute it with "#include<QStringList>".



  • Try to clean and completely rebuild your project. This often helps to "solve" such problems. If the error remains, please provide us with a short, complete, compilable example.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.