Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QTextStream does not return actual string for copy files with QFile
Forum Updated to NodeBB v4.3 + New Features

[Solved] QTextStream does not return actual string for copy files with QFile

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mr_maddog
    wrote on last edited by
    #1

    Hi here is the code.

    @
    QStringList fileList = fileName;
    QStringList NameOfFiles = fileList.replaceInStrings(QRegExp("[^/[0-9a-zA-Z_.]$]"),"");
    QString files;
    QTextStream tmpName;
    foreach(files, fileList) {
    QList<QString>::const_iterator i;
    for (i = NameOfFiles.constBegin(); i != NameOfFiles.constEnd();++i) {
    tmpName << *i << endl;
    }
    QFile::copy(files, outputDir+tmpName.string());

    }
    

    @

    I get always the error overload for 'operator+'
    Whats wrong.

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is outputDir ?

      And what would you like to achieve with your code ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tomma
        wrote on last edited by
        #3

        What type is fileName?
        You create "QTextStream":http://qt-project.org/doc/qt-5.0/qtcore/qtextstream.html tmpName but never assign QString or QIODevice for it.
        You iterate NameOfFiles for every iteration of fileList?
        You stream every string in NameOfFiles to QTextStream tmpName which doesn't have anything to write to.
        In QFile::copy you are calling QTextStream::string() which returns 0 as you haven't set string for QTextStream. You are adding that 0 to outputDir which is propably QString?

        What you are propably trying to do here is copy some input files to new destination without any special characters:
        @
        QStringList files; // add files
        QString outputDir; // add outputdir

        foreach (const QString &fileName, files) {
            QFileInfo f(fileName);
            QString filePath = f.absoluteFilePath();
            QString newFile = outputDir + f.fileName().replace(QRegExp("[^/[0-9a-zA-Z_.]$]"),"");
            QFile::copy(filePath, newFile);
        }
        

        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mr_maddog
          wrote on last edited by
          #4

          Ok sorry i had to point out some things, but yeap thanks to Tomma u get it and [SOLVED].

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved