How to Login to my FTP Account
-
@jsulm said in How to Login to my FTP Account:
@rezaMSLM You did forget.
You're using QFtp class now in your header file, so you need to move#include <QtNetwork/QFtp>
to the header file, else compiler has no idea what QFtp is.
now i have moved it to mainwindow.h
doesn't solved and here are the errors:
@rezaMSLM Do you have this in your pro file:
QT += ftp
You do not link your app against QFtp currently.
Here is an example: https://github.com/qt/qtftp/tree/master/examples/qftp -
@rezaMSLM Do you have this in your pro file:
QT += ftp
You do not link your app against QFtp currently.
Here is an example: https://github.com/qt/qtftp/tree/master/examples/qftp@jsulm said in How to Login to my FTP Account:
@rezaMSLM Do you have this in your pro file:
QT += ftp
You do not link your app against QFtp currently.
Here is an example: https://github.com/qt/qtftp/tree/master/examples/qftpThank you jsulm;
QT+=ftp didnt work
but QT+=network worked!
Now i receive No Error -
I built an object in mainwindow.h file using this command:
class MainWindow... private: QFtp *ftp; }
and call these commands when clicking on "Login" Button:
void MainWindow::on_pushButton_clicked() { ftp->connectToHost("my Host IP"); ftp->login("my user name" , "my password"); }
and when I Run the project and click on Login button it crashes.
but if i change the code like this it won't crash:
class MainWindow... private: QFtp ftp; }
void MainWindow::on_pushButton_clicked() { ftp.connectToHost("my Host IP"); ftp.login("my user name" , "my password"); }
why?
-
I built an object in mainwindow.h file using this command:
class MainWindow... private: QFtp *ftp; }
and call these commands when clicking on "Login" Button:
void MainWindow::on_pushButton_clicked() { ftp->connectToHost("my Host IP"); ftp->login("my user name" , "my password"); }
and when I Run the project and click on Login button it crashes.
but if i change the code like this it won't crash:
class MainWindow... private: QFtp ftp; }
void MainWindow::on_pushButton_clicked() { ftp.connectToHost("my Host IP"); ftp.login("my user name" , "my password"); }
why?
@rezaMSLM Because if you use a pointer you need to create an instance and assign the pointer, else you're using a dangling pointer (a pointer not pointing to a valid chunk of memory). You should read about memory management in C/C++.
MainWindow::MainWindow() { ftp = new QFtp(); }
Why do you want to use a pointer?
-
@rezaMSLM Because if you use a pointer you need to create an instance and assign the pointer, else you're using a dangling pointer (a pointer not pointing to a valid chunk of memory). You should read about memory management in C/C++.
MainWindow::MainWindow() { ftp = new QFtp(); }
Why do you want to use a pointer?
-
when I click on login button and connectToHost() Command is executed how I notice that it's connected?
I know that some signals are emitted but i dont know how to use themMainWindow::MainWindow() { connect(&ftp, SIGNAL(stateChanged(int)), this, SLOT(checkState(int))); } void MainWindow::checkState(int state) { switch(state) { case QFtp::Connected: break; ... } } // From QFtp header file: enum State { Unconnected, HostLookup, Connecting, Connected, LoggedIn, Closing };
-
MainWindow::MainWindow() { connect(&ftp, SIGNAL(stateChanged(int)), this, SLOT(checkState(int))); } void MainWindow::checkState(int state) { switch(state) { case QFtp::Connected: break; ... } } // From QFtp header file: enum State { Unconnected, HostLookup, Connecting, Connected, LoggedIn, Closing };
-
my program has a BUG:
when I'm already Connected to server and I Click on Connect button again none of the buttons will work.
neither login nor disconnect buttonsmy mainwindow.cpp:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QtNetwork/QFtp> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ftp = new QFtp(parent); connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(checkState(int))); } MainWindow::~MainWindow() { delete ui; delete ftp; } void MainWindow::checkState(int state) { switch(state) { case QFtp::Connected: ui->Connect_Status_Label->setText("Connected"); break; case QFtp::Unconnected: ui->Connect_Status_Label->setText("UnConnected"); ui->Login_Status_Label->setText("Logged Out"); break; case QFtp:: LoggedIn: ui->Login_Status_Label->setText("Logged in"); break; } } void MainWindow::on_pushButton_Connect_clicked() { QString Host = ui->lineEdit_Host->text(); ftp->connectToHost(Host); } void MainWindow::on_pushButton_Login_clicked() { QString UserName = ui->lineEdit_User->text(); QString PassWord = ui->lineEdit_Pass->text(); ftp->login(UserName,PassWord); } void MainWindow::on_pushButton_DisConnect_clicked() { ftp->close(); }
what is the reason?
-
my program has a BUG:
when I'm already Connected to server and I Click on Connect button again none of the buttons will work.
neither login nor disconnect buttonsmy mainwindow.cpp:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QtNetwork/QFtp> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ftp = new QFtp(parent); connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(checkState(int))); } MainWindow::~MainWindow() { delete ui; delete ftp; } void MainWindow::checkState(int state) { switch(state) { case QFtp::Connected: ui->Connect_Status_Label->setText("Connected"); break; case QFtp::Unconnected: ui->Connect_Status_Label->setText("UnConnected"); ui->Login_Status_Label->setText("Logged Out"); break; case QFtp:: LoggedIn: ui->Login_Status_Label->setText("Logged in"); break; } } void MainWindow::on_pushButton_Connect_clicked() { QString Host = ui->lineEdit_Host->text(); ftp->connectToHost(Host); } void MainWindow::on_pushButton_Login_clicked() { QString UserName = ui->lineEdit_User->text(); QString PassWord = ui->lineEdit_Pass->text(); ftp->login(UserName,PassWord); } void MainWindow::on_pushButton_DisConnect_clicked() { ftp->close(); }
what is the reason?
@rezaMSLM I don't understand: you're connected and then click connected again? Afterwards disconnect doesn't work? Does disconnect work if you don't click connect when already connected? You should disable the connect button if already connected and enable it when disconnected.
-
@rezaMSLM I don't understand: you're connected and then click connected again? Afterwards disconnect doesn't work? Does disconnect work if you don't click connect when already connected? You should disable the connect button if already connected and enable it when disconnected.
@jsulm said in How to Login to my FTP Account:
you're connected and then click connected again? Afterwards disconnect doesn't work?
yes
@jsulm said in How to Login to my FTP Account:
Does disconnect work if you don't click connect when already connected?
yes
@jsulm said in How to Login to my FTP Account:
You should disable the connect button if already connected and enable it when disconnected.
OK