Skip to content
  • 0 Votes
    6 Posts
    6k Views
    JonBJ
    @VRonin said in Save a text file with Windows/Dos line endings but while preserving encoding in QT.: if you save text use text mode on the device: if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) and if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) everything else comes for free I thought the whole point of his question is precisely that he wants to produce text files which are not native to the OS, specifically he wants Windows \r\n regardless of whether his app is running under Win or Linux. That was why I was saying don't use endl etc., and of course you mustn't use QIODevice::Text. Maybe I misunderstood... :)
  • Reading utf8 QMediaPlaylist

    Solved General and Desktop qmediaplaylist utf-8 utf8
    8
    0 Votes
    8 Posts
    4k Views
    UnitScanU
    [SOLVED] Replace playlist->load(QUrl::fromLocalFile("C:/Users/Marco/Music/default.m3u"), "m3u"); with QFile inputFile("C:/Users/Marco/Music/default.m3u"); if (inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); in.setCodec("UTF-8"); while (!in.atEnd()) { QString line = in.readLine().trimmed().toUtf8().constData(); playlist->addMedia(QUrl(QFileInfo(line).filePath())); } inputFile.close(); } and playlist->save(QUrl::fromLocalFile("C:/Users/Marco/Music/default.m3u"), "m3u"); with QFile outputFile("C:/Users/Marco/Music/default.m3u"); outputFile.open(QIODevice::WriteOnly|QIODevice::Text); for (int i=0; i < playlist->mediaCount(); i++) { //… QTextStream out(&outputFile); out << mediafile[0].toUpper()+mediafile.mid(1) << endl; //… } outputFile.close();
  • 2 Votes
    17 Posts
    12k Views
    Per Gunnar HolmP
    Thanks @kshegunov ! The c_str() was just something we tested along the way! The original code was // Create a Json document from text. Fails for foreign characters! QJsonDocument doc = QJsonDocument::fromJson(msg.toUtf8(), &error); However, all the variations we/I have tried display the same problem (on CentOS 6.5, as we have discovered).