I would suggest to use a class member since it is an async operation. You are having an object on the stack which will be unwound when the function, and for that matter the life cycle of the object, ends.
You have three alternatives to handle this:
Class member
Test::Test(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Test)
{
ui->setupUi(this);
int x = m_ftp.connectToHost("192.168.26.129", 21);
m_ftp.login("User1", "passwd");
}
This version is useful when you need the QFtp object in other method as well.
Smart pointer
Test::Test(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Test)
{
ui->setupUi(this);
QPointer m_ftp = new QFtp());
int x = ftp->connectToHost("192.168.26.129", 21);
ftp->login("User1", "passwd");
}
This version is good when you only need the QFtp object in this method, and the Test class is not a QObject.
QObject parent-child relation
Test::Test(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Test)
{
ui->setupUi(this);
QFtp ftp = new Ftp(this);
int x = ftp->connectToHost("192.168.26.129", 21);
ftp->login("User1", "passwd");
}
This will not work if the "Test" class becomes a non-QObject, but it is good enough when Test inherits that, and you only need the QFtp object in this method.