Qt: datei erstellen



  • QString filename = "data\\test.txt";
    
        QFile file(filename);
    
        if(file.open(QIODevice::WriteOnly))
        {
            QByteArray content = "hallo";
    
            file.write(content);
        }
        else
        {
            QMessageBox fehler;
            fehler.setText("Fehler beim Öffnen der Datei");
            fehler.exec();
        }
    

    Wieso funktioniert das nicht ? Sobald ich ein Verzeichnis angebe, erstellt er mir keine Datei mehr und geht in den else-Teil der if-anweisung.

    mit

    QString filename = "test.txt"
    

    funktioniert es einwandfrei.
    Hat jemand eine Idee ?

    Gruß,
    Prof



  • The file name is usually passed in the constructor, but it can be set at any time using setFileName(). QFile expects the file separator to be '/' regardless of operating system. The use of other separators (e.g., '\') is not supported.

    Quelle: http://doc.trolltech.com/4.7/qfile.html


Anmelden zum Antworten