I have a list of pointers to objects of the items class. How do I access the object’s functions?

I managed to write the data to the objects from the file. But I can’t output this data to the console.

I already wrote-ListtForLoad.first().getName() But can’t get such access

I attach the full code of my program.

#include <QCoreApplication>
#include <QFile>
#include <QString>
#include <QDebug>
#include <QIODevice>
#include <QLinkedList>
#include <QTextStream>

class items : public QObject {

    items(QString name, QString gryp){
        this->name = name;
        this->gryp = gryp;
    QString getName() { 
        return name;
    QString getGryp() { 
        return gryp;
    QString name;
    QString gryp;

int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    QLinkedList<QObject*> ListtForLoad;

    QFile fileIn("myfile.txt");
    QFile fileOut("myfileout.txt");

    int lineCount = 0;
    if (fileIn.open(QIODevice::ReadOnly | QIODevice::Text)){
        lineCount = QTextStream(&fileIn).readAll().split('n').count();
    QString stringAllRead; 

    if(fileIn.open(QIODevice::ReadOnly)) {

        stringAllRead = fileIn.readAll();

        QStringList splitLines = stringAllRead.split("rn");

        for (int countItems = 0; countItems < lineCount; countItems++) {
            QStringList people = splitLines[countItems].split("&"); 
            ListtForLoad << new items( people[0], people[1] ); 

        qDebug() << ListtForLoad.first().getName();

    return a.exec();


You are storing QObject*‘s in the QLinkedList so when you do the below, you get a QObject* back:

ListtForLoad.first()  // <- QObject* here

To derefernce a pointer, you need to use -> instead of . so:


However, QObject doesn’t have a getName() member function.

You should probably store your own type (items) in the list instead:

QLinkedList<items*> ListtForLoad;