Results 1 to 11 of 11

Thread: QFtp...doesnt seems to work ....!!!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QFtp...doesnt seems to work ....!!!

    hey guys....i have written this piece of code for a QFtp application,but this doesnt seem to work....i dont know whr it goes wrong,but it makes a file with 0 byte.......pls,pls any help wud be appreciated....

    Qt Code:
    1. /* main method */
    2.  
    3. #include <QtGui/QApplication>
    4. #include <QApplication>
    5. #include "exftp.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10. exFtp w;
    11.  
    12. w.show();
    13. //a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. /* .h File */
    2.  
    3. #ifndef EXFTP_H
    4. #define EXFTP_H
    5.  
    6. #include <QtGui/QMainWindow>
    7. #include <QFtp>
    8. #include <QUrl>
    9. #include <QFile>
    10. #include <QDialog>
    11. #include <QString>
    12. class QLineEdit;
    13. class QLabel;
    14. //#include "ui_exftp.h"
    15.  
    16. class exFtp : public QDialog
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. exFtp();
    22. ~exFtp();
    23. private:
    24. QFtp *ftp;
    25. QFile file;
    26. QUrl *urlAdd;
    27. QString localFileName;
    28. QLineEdit *ftpServerLineEdit;
    29. QLabel *ftpServerLabel;
    30. QLabel *statusLabel;
    31. QPushButton *downloadButton;
    32. QPushButton *quitButton;
    33. QDialogButtonBox *buttonBox;
    34. QProgressDialog *progressDialog;
    35. //Ui::exFtpClass ui;
    36. private slots:
    37. bool downloadStarted();
    38. void EnabledButton(const QString&);
    39. void ftpDone(bool);
    40. void On_CommandFinished();
    41. };
    42.  
    43. #endif // EXFTP_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /* .cpp file */
    2.  
    3. #include <QtGui>
    4. #include "exftp.h"
    5.  
    6. exFtp::exFtp()
    7. {
    8. ftpServerLabel = new QLabel("FTP");
    9. ftpServerLineEdit = new QLineEdit();
    10. statusLabel = new QLabel();
    11. downloadButton = new QPushButton("Download");
    12. downloadButton->setEnabled(false);
    13. quitButton = new QPushButton("Quit");
    14. buttonBox = new QDialogButtonBox;
    15. buttonBox->addButton(downloadButton,QDialogButtonBox::ActionRole);
    16. buttonBox->addButton(quitButton,QDialogButtonBox::RejectRole);
    17. progressDialog = new QProgressDialog(this);
    18. QHBoxLayout *topLayout = new QHBoxLayout;
    19. topLayout->addWidget(ftpServerLabel);
    20. topLayout->addWidget(ftpServerLineEdit);
    21. QVBoxLayout *mainLayout = new QVBoxLayout;
    22. mainLayout->addLayout(topLayout);
    23. mainLayout->addWidget(statusLabel);
    24. mainLayout->addWidget(buttonBox);
    25. setLayout(mainLayout);
    26. ftp = new QFtp(this);
    27. connect(ftpServerLineEdit,SIGNAL(textEdited(const QString&)),this,SLOT(EnabledButton(const QString&)));
    28. // connect(ftpServerLineEdit,SIGNAL(textEdited(const QString&)),this,SLOT(QUrl(const QString&)))
    29. connect(downloadButton,SIGNAL(clicked()),this,SLOT(downloadStarted()));
    30. connect(ftp,SIGNAL(done(bool)),this,SLOT(ftpDone(bool)));
    31. connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(On_CommandFinished()));
    32. connect(quitButton,SIGNAL(clicked()),this,SLOT(accept()));
    33. //ui.setupUi(this);
    34. }
    35. void exFtp::EnabledButton(const QString& Url)
    36. {
    37. downloadButton->setEnabled(!(Url.isEmpty()));
    38. urlAdd = new QUrl();
    39. urlAdd->setUrl(Url);
    40. urlAdd->setPath(Url);
    41. QFileInfo fi(Url);
    42. localFileName = fi.fileName();
    43. if(localFileName.isEmpty())
    44. localFileName = "exFtp.out";
    45.  
    46. }
    47. void exFtp::On_CommandFinished()
    48. {
    49. file.close();
    50. }
    51. bool exFtp::downloadStarted()
    52. {
    53. file.setFileName(localFileName);
    54. //file.open(QIODevice::WriteOnly);
    55. if(!file.open(QIODevice::WriteOnly))
    56. {
    57. statusLabel->setEnabled(true);
    58. statusLabel->setText(tr("File at %1 cannot be Open/Accesed").arg(localFileName));
    59. return false;
    60. }
    61. ftp->connectToHost(urlAdd->host(),urlAdd->port(21));
    62. ftp->login();
    63. ftp->get(urlAdd->path(),&file);
    64. //ftp->close();
    65. return true;
    66. }
    67. void exFtp::ftpDone(bool fileDone)
    68. {
    69. if(fileDone)
    70. statusLabel->setText("DownLoaded");
    71. else
    72. statusLabel->setText("no,..!!");
    73. }
    74.  
    75. exFtp::~exFtp()
    76. {
    77.  
    78. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by marcel; 23rd February 2008 at 12:48. Reason: missing [code] tags

Similar Threads

  1. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  2. QFtp Trouble !
    By Fastman in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 12:08
  3. Change work area OS
    By pakulo in forum Qt Programming
    Replies: 15
    Last Post: 15th May 2007, 07:20
  4. why the qftp failed in qmainwindow?where is its signal?
    By cxl2253 in forum Qt Programming
    Replies: 15
    Last Post: 22nd April 2007, 13:51
  5. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10

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
  •  
Qt is a trademark of The Qt Company.