![Quote](images/misc/quote_icon.png)
Originally Posted by
liam0connor
i might sound like a newbie but what response would i get from the the waits?
The waitForXYZ methods return true if the signal has been emitted or false if that was not the case.
![Quote](images/misc/quote_icon.png)
Originally Posted by
liam0connor
And do you have any idea as to how i could change to code to maybe try non blocking communication
By connecting to the signals instead of using the waitFor methods.
Usually the pattern is a "Command" or "Job", an object that encapsulates the steps necessary to achieve the goal.
Something like
class RebootCommand
: public QObject{
Q_OBJECT
public:
explicit RebootCommand
(QObject *parent
= nullptr
);
void start
(const QString &host,
int port
);
signals:
void finished();
private slots:
void onConnected();
void onReadyRead();
private:
enum State {
Disconnected,
WaitingForUserPrompt1,
WaitingForPasswordPrompt1,
WaitingForUserPrompt2,
WaitingForPasswordPrompt2
};
State m_state = Disconnected;
};
class RebootCommand : public QObject
{
Q_OBJECT
public:
explicit RebootCommand(QObject *parent = nullptr);
void start(const QString &host, int port);
signals:
void finished();
private slots:
void onConnected();
void onReadyRead();
private:
enum State {
Disconnected,
WaitingForUserPrompt1,
WaitingForPasswordPrompt1,
WaitingForUserPrompt2,
WaitingForPasswordPrompt2
};
State m_state = Disconnected;
QTcpSocket *m_socket = nullptr;
};
To copy to clipboard, switch view to plain text mode
Cheers,
_
Bookmarks