Results 1 to 9 of 9

Thread: QFile copy connect bytesWritten

  1. #1
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QFile copy connect bytesWritten

    Hi all,

    short question with simple code:

    Qt Code:
    1. QFile from("/home/chris/backup.tar.bz2");
    2. QFile to("/home/chris/Test/backup.tar.bz2");
    3.  
    4. connect(&to, SIGNAL(bytesWritten(qint64)), this, SLOT(onWrite(qint64)));
    5.  
    6. from.copy(to.fileName());
    7.  
    8. (...)
    9.  
    10. void MyClass::onWrite(qint64 bytes) {
    11. qDebug() << bytes;
    12. }
    To copy to clipboard, switch view to plain text mode 

    The file will be copied, but no bytes are shown! Why?

    Thx!
    Chris

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QFile copy connect bytesWritten

    bytes will be copied if you copy them, i don't see any copying code.

    byteWritten() i emitted when bytes are written to the file, you should connect to this signal (shich you have already done), now in the onWrite() slot, you should copy the bytes

    -Reply Recalled
    Last edited by Santosh Reddy; 25th May 2011 at 14:58.

  3. #3
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile copy connect bytesWritten

    Line 6: from.copy(to.fileName()); ?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile copy connect bytesWritten

    Quote Originally Posted by realdarkman71 View Post
    Line 6: from.copy(to.fileName()); ?
    1. I think that from.copy() don't use Yours to QFile object but creates new one.
    2. From QFile doc : Unlike other QIODevice implementations, such as QTcpSocket, QFile does not emit the aboutToClose(), bytesWritten(), or readyRead() signals.

  5. #5
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile copy connect bytesWritten

    Ups, I did not seen this hint in the doc!

    What can I use? Any hints?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QFile copy connect bytesWritten

    You try using QFileSystemWatcher on the destination QFile object.
    EDIT:
    This will also not work if you use QFile::copy().

    What exactly do you need?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile copy connect bytesWritten

    ...a progress bar for copy process! Not file to file, copied bytes per file!

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile copy connect bytesWritten

    Look at QtCopyDialog.

  9. #9
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile copy connect bytesWritten

    Ok, thanks for the hint!

Similar Threads

  1. QFile::copy copies only 3kb
    By camol in forum Qt Programming
    Replies: 36
    Last Post: 20th April 2011, 19:52
  2. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  3. void QIODevice::bytesWritten
    By Magu in forum Newbie
    Replies: 3
    Last Post: 25th November 2009, 09:02
  4. QBuffer bytesWritten() problem
    By QAlex in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 09:05
  5. QTemporaryFile and Qfile::copy()
    By ChrisW67 in forum Newbie
    Replies: 2
    Last Post: 23rd April 2009, 23:32

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.