Results 1 to 20 of 20

Thread: Qftp Put Image to FTP

  1. #1
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Qftp Put Image to FTP

    I am working with a screenshot upload method for a gaming client, its my first QT project and QT is growing on me fast, I like it! While the client is running, I want to upload screenshots to our ftp. I have looked into the documentation and have set up my project to add the QtNetwork for QFtp.
    The problem is everything seems to be working correctly, but after the code has been executed, there is not a image.png in my ftp.

    Qt Code:
    1. void PGC::shootScreen()
    2. {
    3.  
    4. originalPixmap = QPixmap(); // clear image for low memory situations
    5.  
    6. originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
    7.  
    8. QImage image;
    9. image = originalPixmap.toImage();
    10. QBuffer buffer(&ba);
    11. buffer.open(QIODevice::WriteOnly);
    12. image.save(&buffer, "PNG"); // writes image into ba in PNG format
    13.  
    14.  
    15.  
    16. if (!originalPixmap.save("test.png")) {
    17. // Saving didn't work
    18. QMessageBox::warning(this, "Saving error", "Could not save the file. Check the plugins!");
    19. }
    20.  
    21. QFtp* connection = new QFtp();
    22. QObject::connect(connection, SIGNAL(done(bool)), this, SLOT(quit()));
    23. connection->connectToHost(ftphost);
    24. connection->login(user, password);
    25. //connection->cd("SS");
    26.  
    27. if (!connection->put(ba, "test.png", QFtp::Binary)) {
    28. // FTP SS didn't work
    29. QMessageBox::warning(this, "FTP SS Error", "Could not save the SS to FTP!");
    30. }
    31.  
    32. connection->close( );
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by harleyskater; 28th June 2010 at 06:10.

  2. #2
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    I also just tried this route. Nothing in the ftp either

    Qt Code:
    1. void PGC::shootScreen()
    2. {
    3.  
    4. QDateTime dt = QDateTime::currentDateTime();
    5.  
    6. QString *dtStr = new QString();
    7. *dtStr = dt.toString("ddMMyyyy_hhmmss");
    8.  
    9. QString format = "png";
    10. QString filename = "";
    11.  
    12. filename = *dtStr + tr("_PGC.") + format;
    13.  
    14.  
    15. originalPixmap = QPixmap(); // clear image for low memory situations
    16. // on embedded devices.
    17. originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
    18. updateScreenshotLabel();
    19.  
    20. QImage image;
    21. image = originalPixmap.toImage();
    22. QBuffer buffer(&ba);
    23. buffer.open(QIODevice::WriteOnly);
    24. image.save(&buffer, "PNG"); // writes image into ba in PNG format
    25.  
    26.  
    27.  
    28. if (!originalPixmap.save("test.png")) {
    29. // Saving didn't work
    30. QMessageBox::warning(this, "Saving error", "Could not save the file. Check the plugins!");
    31. }
    32.  
    33. QFtp* connection = new QFtp();
    34. QObject::connect(connection, SIGNAL(done(bool)), this, SLOT(quit()));
    35. connection->connectToHost(ftphost);
    36. connection->login(user, password);
    37. //connection->cd("SS");
    38.  
    39. if (!connection->put(ba, "test.png", QFtp::Binary)) {
    40. // FTP SS didn't work
    41. QMessageBox::warning(this, "FTP SS Error", "Could not save the SS to FTP!");
    42. }
    43.  
    44. QFile *file = new QFile("test.png", this);
    45. file->open(QFile::ReadOnly);
    46.  
    47. if (!connection->put(file, "test.png")) {
    48. // FTP SS didn't work
    49. QMessageBox::warning(this, "FTP SS Error2", "Could not save the SS to FTP!");
    50. }
    51.  
    52. connection->close( );
    53.  
    54. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by harleyskater; 28th June 2010 at 08:18.

  3. #3
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    Is there a way to check the ftp->put command for progress? or file size or mime type?

  4. #4
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qftp Put Image to FTP

    Quote Originally Posted by harleyskater View Post
    Is there a way to check the ftp->put command for progress? or file size or mime type?
    What version of Qt are you running? In 4.6.3, there is a dataTransferProgress() function in QFtp.

    As for the QFtp:ut() function, your if statement is going to return immediately if the command was scheduled. You need to check the QFtp::done() and QFtp::error() functions for the status of the transfer.
    Amos
    Qt Programmer Extraordinaire

    Current Work:
    Ripxx Sports Measurement Device - www.ripxx.com
    (Featured in MYTHBUSTERS on 2010-05-19 in S08E08)

  5. The following user says thank you to amoswood for this useful post:

    harleyskater (28th June 2010)

  6. #5
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    I went through the documentation and I set some breakpoints on the ftp.error and ftp.currentcommand so I could let some time pass between hits.

    They all return the same thing

    error = 0 //no error
    current = 3 // QFtp::ConnectToHost - connectToHost() is being executed.



    Qt Code:
    1. void PGC::shootScreen()
    2. {
    3.  
    4. QDateTime dt = QDateTime::currentDateTime();
    5.  
    6. QString *dtStr = new QString();
    7. *dtStr = dt.toString("ddMMyyyy_hhmmss");
    8.  
    9. QString format = "png";
    10. QString filename = "";
    11.  
    12. filename = *dtStr + tr("_PGC.") + format;
    13.  
    14.  
    15. originalPixmap = QPixmap(); // clear image for low memory situations
    16. // on embedded devices.
    17. originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
    18. updateScreenshotLabel();
    19.  
    20. QImage image;
    21. image = originalPixmap.toImage();
    22. QBuffer buffer(&ba);
    23. buffer.open(QIODevice::WriteOnly);
    24. image.save(&buffer, "PNG"); // writes image into ba in PNG format
    25.  
    26.  
    27.  
    28. if (!originalPixmap.save("test.png")) {
    29. // Saving didn't work
    30. QMessageBox::warning(this, "Saving error", "Could not save the file. Check the plugins!");
    31. }
    32.  
    33. QFtp* connection = new QFtp();
    34. QObject::connect(connection, SIGNAL(done(bool)), this, SLOT(quit()));
    35. connection->connectToHost(ftphost);
    36. connection->login(user, password);
    37.  
    38. //connection->cd("SS");
    39.  
    40. if (!connection->put(ba, "test.png", QFtp::Binary)) {
    41. // FTP SS didn't work
    42. QMessageBox::warning(this, "FTP SS Error", "Could not save the SS to FTP!");
    43. }
    44.  
    45. /*QFile *file = new QFile("test.png", this);
    46.  
    47. if (!file->open(QFile::ReadOnly))
    48. {
    49. // FTP SS didn't work
    50. QMessageBox::warning(this, "FTP SS Error3", "Could not open the SS !");
    51. file->close();
    52. delete file;
    53. }
    54.  
    55. if (!connection->put(file, "test.png")) {
    56. // FTP SS didn't work
    57. QMessageBox::warning(this, "FTP SS Error2", "Could not save the SS to FTP!");
    58. } */
    59.  
    60. QVariant ftperror = connection->error();
    61. QVariant ftpcurrent = connection->currentCommand();
    62. ftperror = connection->error();
    63. ftpcurrent = connection->currentCommand();
    64. ftperror = connection->error();
    65. ftpcurrent = connection->currentCommand();
    66. ftperror = connection->error();
    67. ftpcurrent = connection->currentCommand();
    68. ftperror = connection->error();
    69. ftpcurrent = connection->currentCommand();
    70.  
    71.  
    72. connection->close( );
    73.  
    74. }
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qftp Put Image to FTP

    The QFtp class works asynchronously to transfer data. So, calling the connecToHost, put, error, currentCommand, and close functions sequentially will never actually execute any of the commands. What you need to do is write a class so that you can use signals and slots. Catching the signals after you start transferring is the key. The example listed in the QFtp detailed description gives some clarification to your issue.

    Hope this helps.
    Amos
    Qt Programmer Extraordinaire

    Current Work:
    Ripxx Sports Measurement Device - www.ripxx.com
    (Featured in MYTHBUSTERS on 2010-05-19 in S08E08)

  8. #7
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    I also noticed, because I tried to show a friend what I was working on by passing him the build exe that anywhere I put "ftp = new QFtp();" it crashes the app but when I execute it through the IDE it doesn't crash. I have the project setup for ftp.

  9. #8
    Join Date
    Apr 2010
    Posts
    34
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qftp Put Image to FTP

    Just put the command connection->close( ); to a slot catching the done() signal. You're closing the connection before the actions are executed.

  10. The following user says thank you to Vit Stepanek for this useful post:

    harleyskater (29th June 2010)

  11. #9
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    Thank you Vit! I wasn't sure how that connection->close( ); would execute and when! but you are right. works great now! except for the problem where it won't execute outside of the IDE. I debugged in release mode and it runs from the IDE and it works, uploads to the FTP, but if I execute it outside of the IDE it crashes when it hits the FTP code.

  12. #10
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    I found this page for documentation,

    http://doc.trolltech.com/4.3/deployment-windows.html

    The only thing I saw for Visual Studios that I wasn't doing was copying the plugins DIR to my release folder.

    I copied the entire Plugins dir to my release dir and I have the same problem

  13. #11
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    still no advice on this? because im still stuck.

  14. #12
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    Well, Qt Creator executes the exe too, so if it crashes outside of Qt Creator, then your environment is different (eg. path)

  15. #13
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    Okay I went back and set my Output Directory so my exe goes into the same folder as the rest of my release

    now when I compile, my exe goes to my Projects /Release Folder and not my Solutions.

    My program is still crashing outside of my IDE, and I believe you are right that its my envirornment outside of my IDE that is causing the crash but I am not sure what part of my environment.

    It is crashing at this line. I have in my project the need to include a lot of dll's but I am thinking it would be the Network DLL that would be causing the problem since it is crashing at this line: QFtp *connectionftp = new QFtp(this);

    I am attaching a screenshot of my release folder
    Attached Images Attached Images
    Last edited by harleyskater; 7th July 2010 at 05:03.

  16. #14
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    project stilllll isn't working did anyone take a look at that screenshot? is it possible its the library and not the dll?

  17. #15
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    Where do you output that error?

  18. #16
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    that error is actually just a message box I put before and after the line of code that is failing to track down where the app is failing, kinda like a die statement.

    QFtp *connectionftp = new QFtp(this);

  19. #17
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    So you took a picture of a message box you created yourself and are asking us why that message box appears?

  20. #18
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    no, I am wondering why my program crashes when it reaches this line of code

    QFtp *connectionftp = new QFtp(this);

    I took the screenshot only to show that I have all the dll's located in the builds dir.

    It executes great when ran within MSVS2008 but the exe outside of the IDE crashes on that line. I took the screenshot to show I am including what I need to.

  21. #19
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qftp Put Image to FTP

    Well, MSVS2008 doesn't run your program from the "Release" dir, it's runs it from your projects home directory (which is typically where your source code is) so it's not using the DLLs in your release directory when its running from within the IDE.

    So, delete all the files in the release directory. All of them. Then do a full rebuild and see if it works then, from a VS2008 command prompt. If it does, there's something wrong with one of the DLLs which was there.

  22. #20
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qftp Put Image to FTP

    Any body please look into my thread "Slow FTP Program using QFtp" Its very Urgent and Please help me.

    Thanks in advance

Similar Threads

  1. QFtp and dataTransferProgress
    By racinglocura07 in forum Qt Programming
    Replies: 2
    Last Post: 24th June 2010, 18:14
  2. Synchronous QFtp?
    By aarpon in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2009, 09:28
  3. QFtp over QHttp
    By parusri in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2009, 19:16
  4. Synchronizing QFtp
    By arun_vj in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 12:31
  5. Replies: 0
    Last Post: 23rd September 2007, 11:54

Tags for this Thread

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.