Question

The problem occurs when I define a struct like the following one

struct TInputData
{
    QString      filename;
    QFile        file;
    QTextStream  stream;
};

then I put this into a QVector container as follows:

QVector<struct TInputData> input(DATA_SOURCE_END);

after that I invoke some methods of the vector member fields:

for(int i = 0; i < DATA_SOURCE_END; ++i)
{
    input[i].filename = QString(argv[i + 1]);
    input[i].file.setFileName(input[i].filename);
    if (!input[i].file.open(QIODevice::ReadOnly))
    {
        QDebug(QtCriticalMsg) << "Failed to open input file: " << input[i].filename << "!!!";
        return a.exec();
    }
    input[i].stream.setDevice(&input[i].file);
    qDebug() << "Connected to input file " << input[i].filename;
}

I am getting the following compilation error:

/usr/include/qt4/QtCore/qfile.h:209: error: 'QFile::QFile(const QFile&)' is private 
within this context <at line where struct TInputData is declared>

And just the same regarding QTextStream.

So what am I missing?

Thanks in advance for your help.

UPDATE

The solution offered by @Ashot is to manually create TInputData objects. But it introduces some additional memory management difficulties. The workaround is smart pointers usage.

Was it helpful?

Solution

Change QVector<struct TInputData> input(DATA_SOURCE_END); to QVector<TInputData*> input(DATA_SOURCE_END);

QVector need to copy of its content, but copy constructor of QFile is private, it cant be copied.

When using pointers you should manually new and delete your TInputData objects or you can use smart pointers for it.

You can try QSharedPointer http://qt-project.org/doc/qt-4.8/qsharedpointer.html#QSharedPointer-2. Your vector will be QVector<QSharedPointer<TInputData> > input(DATA_SOURCE_END)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top