Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to Login to my FTP Account
Forum Updated to NodeBB v4.3 + New Features

How to Login to my FTP Account

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 3 Posters 7.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R rezaMSLM

    @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:
    0_1519933030240_Capture.JPG

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #16

    @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

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    R 1 Reply Last reply
    3
    • jsulmJ jsulm

      @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

      R Offline
      R Offline
      rezaMSLM
      wrote on last edited by
      #17

      @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/qftp

      Thank you jsulm;
      QT+=ftp didnt work
      but QT+=network worked!
      Now i receive No Error

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rezaMSLM
        wrote on last edited by rezaMSLM
        #18

        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?

        jsulmJ 1 Reply Last reply
        0
        • R rezaMSLM

          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?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #19

          @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?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          1
          • jsulmJ jsulm

            @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?

            R Offline
            R Offline
            rezaMSLM
            wrote on last edited by
            #20

            @jsulm I even don't know when I have to use pointer and when not!!!

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rezaMSLM
              wrote on last edited by
              #21

              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 them

              jsulmJ 1 Reply Last reply
              0
              • R rezaMSLM

                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 them

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #22

                @rezaMSLM

                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
                };
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                R 1 Reply Last reply
                2
                • jsulmJ jsulm

                  @rezaMSLM

                  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
                  };
                  
                  R Offline
                  R Offline
                  rezaMSLM
                  wrote on last edited by
                  #23

                  @jsulm Thanks alot

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rezaMSLM
                    wrote on last edited by
                    #24

                    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 buttons

                    my 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?

                    jsulmJ 1 Reply Last reply
                    0
                    • R rezaMSLM

                      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 buttons

                      my 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?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #25

                      @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.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      R 1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @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.

                        R Offline
                        R Offline
                        rezaMSLM
                        wrote on last edited by
                        #26

                        @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

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved