Results 1 to 3 of 3

Thread: error: ‘QFile::QFile(const QFile&)’ is private by using a foreach

  1. #1
    Join Date
    Jul 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default error: ‘QFile::QFile(const QFile&)’ is private by using a foreach

    Hey guys,

    I got this error message by trying to use my code under linux.

    Qt Code:
    1. QStringList files = searchFiles(filepath);
    2. foreach(QFile foundFile, files) {
    3. // operations...
    4. }
    To copy to clipboard, switch view to plain text mode 

    Does anyone know a reason for that. I really don't want to change all of code.

    thx in advance

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: error: ‘QFile::QFile(const QFile&)’ is private by using a foreach

    The error message is self explanatory. You cannot copy a QFile (or any other QObject), and the copy constructor has been made private to enforce this. foreach() will be implicitly converting each string in your list to a QFile in a way that tries to invoke the copy constructor, e.g.
    Qt Code:
    1. QFile foundFile = QString("test");
    To copy to clipboard, switch view to plain text mode 
    Your loop needs to be:
    Qt Code:
    1. foreach(const QString &name, files) {
    2. QFile foundFile(name);
    3. // operations...
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error: ‘QFile::QFile(const QFile&)’ is private by using a foreach

    Ok nice that works. Thx

Similar Threads

  1. Replies: 4
    Last Post: 9th May 2011, 09:52
  2. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  3. Binary QFile error
    By Affenbrotbaum in forum Newbie
    Replies: 3
    Last Post: 29th January 2010, 02:13
  4. Replies: 0
    Last Post: 4th November 2009, 10:21
  5. QFile using utf-8
    By Mr.QT in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2009, 12:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.