QFile::QFile function --> Error: QFile :: QFile (const QFile &) 'is private

青春壹個敷衍的年華 提交于 2019-12-11 04:04:02

问题


In one of my methods I need a QFile Object:

    void GUIsubclassKuehniGUI::LoadDirectory()   
    {
        QString loadedDirectory = QFileDialog::getExistingDirectory(this,
                                                    "/home",tr("Create Directory"),
                                                    QFileDialog::DontResolveSymlinks);
        ui.PathDirectory -> setText(loadedDirectory);

        QFileInfo GeoDat1 = loadedDirectory + "/1_geo.m4";  
        QFileInfo GeoDat2 = loadedDirectory + "/2_geo.m4";         
        QString Value;

        if (GeoDat1.exists() == true)
        {
            QFile GEO = (loadedDirectory + "/1_geo.m4");   // ERROR LINE HERE!

            if(GEO.open(QIODevice::ReadOnly | QIODevice::Text))    
            {
                QTextStream Stream (&GEO); 
                QString Text;
                do
                {
                    Text = Stream.readLine();

                    QString startWith = "start";
                    QString endWith = "stop" ;                                      
                    int start = Text.indexOf(startWith, 0, Qt::CaseInsensitive); 
                    int end = Text.indexOf(endWith, Qt::CaseInsensitive);        

                    if (start != -1)                                            
                        Value = Text.mid(start + startWith.length(), end - ( start + startWith.length() ) );


                    double ValueNumber = Value.toDouble();
                    ValueNumber = ui.ValueLineEdit->value();
                }
                while(!Text.isNull());
                GEO.close();
            }
       }
       else if (GeoDat2.exists() == true)
       {
           ...
       }
   }

The problem is the line I marked with "// ERROR LINE HERE!". When compiling I get the error message: QFile :: QFile (const QFile &) 'is private. I don't understand this, because in the QFile documentary the function is declared as public. Can someone tell me how to fix that?


回答1:


Replace:

QFile GEO = (loadedDirectory + "/1_geo.m4");

with this line:

QFile GEO(loadedDirectory + "/1_geo.m4");



回答2:


what you did here

QFile GEO = (loadedDirectory + "/1_geo.m4");

was using the assignment operator to create a QFile from a path, which is not possible

you should use the constructor like this

QFile GEO(loadedDirectory + "/1_geo.m4");



回答3:


Remove the equals sign to do direct-initialization.



来源:https://stackoverflow.com/questions/9601821/qfileqfile-function-error-qfile-qfile-const-qfile-is-private

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!