Home

QtTelnet Class Reference

The QtTelnet class proveds an API to connect to Telnet servers, issue commands and receive replies. More...

 #include <QtTelnet>

Inherits QObject.

Public Types

Public Functions

Public Slots

Signals

Additional Inherited Members


Detailed Description

The QtTelnet class proveds an API to connect to Telnet servers, issue commands and receive replies.

When a QtTelnet object has been created, you need to call connectToHost() to establish a connection with a Telnet server. When the connection is established the connected() signal is emitted. At this point you should call login(). The QtTelnet object will emit connectionError() if the connection fails, and authenticationFailed() if the login() failed.

Once the connection has been successfully established and you've logged in you can send control messages using sendControl() and data using sendData(). Connect to the message() signal to receive data from the Telnet server. The connection is closed with close().

You can use your own socket if you call setSocket() before connecting. The socket used by QtTelnet is available from socket().


Member Type Documentation

enum QtTelnet::Control

This enum specifies control messages you can send to the Telnet server using sendControl().

ConstantValueDescription
QtTelnet::GoAhead0Sends the GO AHEAD control message, meaning that the server can continue to send data.
QtTelnet::InterruptProcess1Interrupts the current running process on the server. This is the equivalent of pressing Ctrl+C in most terminal emulators.
QtTelnet::AreYouThere2Sends the ARE YOU THERE control message, to check if the connection is still alive.
QtTelnet::AbortOutput3Temporarily suspends the output from the server. The output will resume if you send this control message again.
QtTelnet::EraseCharacter4Erases the last entered character.
QtTelnet::EraseLine5Erases the last line.
QtTelnet::Break6Sends the BREAK control message.
QtTelnet::EndOfFile7Sends the END OF FILE control message.
QtTelnet::Suspend8Suspends the current running process on the server. Equivalent to pressing Ctrl+Z in most terminal emulators.
QtTelnet::Abort9Sends the ABORT control message.

See also sendControl().


Member Function Documentation

QtTelnet::QtTelnet ( QObject * parent = 0 )

Constructs a QtTelnet object.

You must call connectToHost() before calling any of the other member functions.

The parent is sent to the QObject constructor.

See also connectToHost().

QtTelnet::~QtTelnet ()

Destroys the QtTelnet object. This will also close the connection to the server.

See also logout().

void QtTelnet::close ()   [slot]

Closes the connection to a Telnet server.

See also connectToHost() and login().

void QtTelnet::connectToHost ( const QString & host, quint16 port = 23 )

Calling this function will make the QtTelnet object attempt to connect to a Telnet server specified by the given host and port.

The connected() signal is emitted if the connection succeeds, and the connectionError() signal is emitted if the connection fails. Once the connection is establishe you must call login().

See also close().

void QtTelnet::connectionError ( QAbstractSocket::SocketError error )   [signal]

This signal is emitted if the underlying socket implementation receives an error. The error argument is the same as being used in QSocket::connectionError()

bool QtTelnet::isValidWindowSize () const

Returns true if the window size is valid, i.e. windowSize().isValid() returns true; otherwise returns false.

See also setWindowSize().

void QtTelnet::loggedIn ()   [signal]

This signal is emitted when you have been logged in to the server as a result of the login() command being called. Do note that you might never see this signal even if you have been logged in, due to the Telnet specification not requiring Telnet servers to notify clients when users are logged in.

See also login() and setPromptPattern().

void QtTelnet::loggedOut ()   [signal]

This signal is emitted when you have called logout() and the Telnet server has actually logged you out.

See also logout() and login().

void QtTelnet::login ( const QString & username, const QString & password )

Sets the username and password to be used when logging in to the server.

See also setLoginPattern() and setPasswordPattern().

void QtTelnet::loginFailed ()   [signal]

This signal is emitted when the login has failed. Do note that you might in certain cases see several loginRequired() signals being emitted but no loginFailed() signals. This is due to the Telnet specification not requiring the Telnet server to support reliable authentication methods.

See also login() and loginRequired().

void QtTelnet::loginRequired ()   [signal]

This signal is emitted when the QtTelnet class sees that the Telnet server expects authentication and you have not already called login().

As a reply to this signal you should either call login() or logout()

See also login() and logout().

void QtTelnet::logout ()   [slot]

This function will log you out of the Telnet server. You cannot send any other data after sending this command.

See also login(), sendData(), and sendControl().

void QtTelnet::message ( const QString & data )   [signal]

This signal is emitted when the QtTelnet object receives more data from the Telnet server.

See also sendData().

void QtTelnet::sendControl ( Control ctrl )   [slot]

Sends the control message ctrl to the Telnet server the QtTelnet object is connected to.

See also Control, sendData(), and sendSync().

void QtTelnet::sendData ( const QString & data )   [slot]

Sends the string data to the Telnet server. This is often a command the Telnet server will execute.

See also sendControl().

void QtTelnet::sendSync ()   [slot]

Sends the Telnet SYNC sequence, meaning that the Telnet server should discard any data waiting to be processed once the SYNC sequence has been received. This is sent using a TCP urgent notification.

See also sendControl().

void QtTelnet::setLoginPattern ( const QRegExp & pattern )

Sets the expected login pattern.

The pattern is used to automatically recognize when the server asks for a username. If no username has been set, the loginRequired() signal will be emitted.

See also login().

void QtTelnet::setLoginString ( const QString & login )

Sets the expected login string to login.

This is an overloaded function.

void QtTelnet::setPasswordPattern ( const QRegExp & pattern )

Sets the expected password prompt pattern.

The pattern is used to automatically recognize when the server asks for a password. If no password has been set, the loginRequired() signal will be emitted.

See also login().

void QtTelnet::setPasswordString ( const QString & pattern )

Sets the expected password prompt to pattern.

This is an overloaded function.

void QtTelnet::setPromptPattern ( const QRegExp & pattern )

Sets the expected shell prompt pattern.

The pattern is used to automatically recognize when the client has successfully logged in. When a line is read that matches the pattern, the loggedIn() signal will be emitted.

See also login() and loggedIn().

void QtTelnet::setPromptString ( const QString & pattern )

Sets the expected shell prompt to pattern.

This is an overloaded function.

void QtTelnet::setSocket ( QTcpSocket * socket )

Set the socket to be used in the communication.

This function allows you to use your own QSocket subclass. You should call this function before calling connectToHost(); if you call it after a connection has been established the connection will be closed, so in all cases you will need to call connectToHost() after calling this function.

See also socket(), connectToHost(), and logout().

void QtTelnet::setWindowSize ( const QSize & size )

Sets the client window size to size.

The width and height are given in number of characters. Non-visible clients should pass an invalid size (i.e. QSize()).

See also windowSize() and isValidWindowSize().

void QtTelnet::setWindowSize ( int width, int height )

Sets the client window size.

The width and height are given in number of characters.

This is an overloaded function.

QTcpSocket * QtTelnet::socket () const

Returns the QTcpSocket instance used by this telnet object.

See also setSocket().

QSize QtTelnet::windowSize () const

Returns the window's size. This will be an invalid size if the Telnet server is not using the NAWS option (RFC1073).

See also setWindowSize() and isValidWindowSize().


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt Solutions