2

在我的一种方法中,我需要一个 QFile 对象:

    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)
       {
           ...
       }
   }

问题是我用“// ERROR LINE HERE! ”标记的那一行。编译时我收到错误消息:QFile :: QFile (const QFile &) 'is private。我不明白这一点,因为在 QFile 纪录片中,该函数被声明为 public。有人可以告诉我如何解决吗?

4

3 回答 3

6

代替:

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

用这条线:

QFile GEO(loadedDirectory + "/1_geo.m4");
于 2012-03-07T12:52:17.050 回答
3

你在这里做了什么

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

正在使用赋值运算符从路径创建 QFile,这是不可能的

你应该像这样使用构造函数

QFile GEO(loadedDirectory + "/1_geo.m4");
于 2012-03-07T12:53:13.153 回答
2

删除等号进行直接初始化

于 2012-03-07T12:52:33.513 回答