Tests: Use Qt5-style connects

The heavy lifting was done by clazy.

Change-Id: If3332a2b4a6d011d2cb74996f5dd750452093f31
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Orgad Shaneh
2016-06-27 22:34:13 +03:00
committed by Orgad Shaneh
parent 4d9f79964d
commit 847637708f
25 changed files with 137 additions and 137 deletions

View File

@@ -149,7 +149,7 @@ static QmlDesigner::Model* createModel(const QString &typeName, int major = 2, i
QmlDesigner::Model *model = QmlDesigner::Model::create(typeName.toUtf8(), major, minor, metaInfoPropxyModel);
QPlainTextEdit *textEdit = new QPlainTextEdit;
QObject::connect(model, SIGNAL(destroyed()), textEdit, SLOT(deleteLater()));
QObject::connect(model, &QObject::destroyed, textEdit, &QObject::deleteLater);
textEdit->setPlainText(QString("import %1 %3.%4; %2{}").arg(typeName.split(".").first())
.arg(typeName.split(".").last())
.arg(major)

View File

@@ -85,8 +85,8 @@ ModelTestWidget::ModelTestWidget(CallgrindWidgetHandler *handler)
m_format->addItem("absolute", CostDelegate::FormatAbsolute);
m_format->addItem("relative", CostDelegate::FormatRelative);
m_format->addItem("rel. to parent", CostDelegate::FormatRelativeToParent);
connect(m_format, SIGNAL(activated(int)),
this, SLOT(formatChanged(int)));
connect(m_format, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
this, &ModelTestWidget::formatChanged);
h->addWidget(m_format);
QDoubleSpinBox *minimumCost = new QDoubleSpinBox;
@@ -94,8 +94,8 @@ ModelTestWidget::ModelTestWidget(CallgrindWidgetHandler *handler)
minimumCost->setRange(0, 1);
minimumCost->setDecimals(4);
minimumCost->setSingleStep(0.01);
connect(minimumCost, SIGNAL(valueChanged(double)),
m_handler->proxyModel(), SLOT(setMinimumInclusiveCostRatio(double)));
connect(minimumCost, &QDoubleSpinBox::valueChanged,
m_handler->proxyModel(), &DataProxyModel::setMinimumInclusiveCostRatio);
minimumCost->setValue(0.0001);
h->addWidget(minimumCost);

View File

@@ -10,7 +10,7 @@ MyType::MyType(QObject *parent)
updateTimerText();
m_timer = new QTimer(this);
m_timer->setInterval(1000);
connect(m_timer, SIGNAL(timeout()), SLOT(updateTimerText()));
connect(m_timer, &QTimer::timeout, this, &MyType::updateTimerText);
m_timer->start();
}

View File

@@ -20,10 +20,9 @@ public:
signals:
void timeChanged(const QString &newText);
private slots:
private:
void updateTimerText();
private:
QString m_timeText;
QTimer *m_timer;

View File

@@ -10,7 +10,7 @@ MyType::MyType(QObject *parent)
updateTimerText();
m_timer = new QTimer(this);
m_timer->setInterval(1000);
connect(m_timer, SIGNAL(timeout()), SLOT(updateTimerText()));
connect(m_timer, &QTimer::timeout, this, &MyType::updateTimerText);
m_timer->start();
}

View File

@@ -20,10 +20,9 @@ public:
signals:
void timeChanged(const QString &newText);
private slots:
private:
void updateTimerText();
private:
QString m_timeText;
QTimer *m_timer;

View File

@@ -1792,10 +1792,10 @@ namespace qobject {
parent.setObjectName("A Parent");
QObject child(&parent);
child.setObjectName("A Child");
QObject::connect(&child, SIGNAL(destroyed()), &parent, SLOT(deleteLater()));
QObject::connect(&child, SIGNAL(destroyed()), &child, SLOT(deleteLater()));
QObject::disconnect(&child, SIGNAL(destroyed()), &parent, SLOT(deleteLater()));
QObject::disconnect(&child, SIGNAL(destroyed()), &child, SLOT(deleteLater()));
QObject::connect(&child, &QObject::destroyed, &parent, &QObject::deleteLater);
QObject::connect(&child, &QObject::destroyed, &child, &QObject::deleteLater);
QObject::disconnect(&child, &QObject::destroyed, &parent, &QObject::deleteLater);
QObject::disconnect(&child, &QObject::destroyed, &child, &QObject::deleteLater);
child.setObjectName("A renamed Child");
BREAK_HERE;
// Check child "A renamed Child" QObject.
@@ -1889,11 +1889,11 @@ namespace qobject {
QObject ob1;
ob1.setObjectName("Another Object");
QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));
QObject::connect(&ob1, SIGNAL(destroyed()), &ob, SLOT(deleteLater()));
QObject::connect(&ob, &QObject::destroyed, &ob1, &QObject::deleteLater);
QObject::connect(&ob1, &QObject::destroyed, &ob, &QObject::deleteLater);
BREAK_HERE;
QObject::disconnect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));
QObject::disconnect(&ob1, SIGNAL(destroyed()), &ob, SLOT(deleteLater()));
QObject::disconnect(&ob, &QObject::destroyed, &ob1, &QObject::deleteLater);
QObject::disconnect(&ob1, &QObject::destroyed, &ob, &QObject::deleteLater);
dummyStatement(&ob, &ob1);
#endif
}
@@ -1930,7 +1930,6 @@ namespace qobject {
Q_OBJECT
public:
Receiver() { setObjectName("Receiver"); }
public slots:
void aSlot() {
QObject *s = sender();
if (s) {
@@ -1945,7 +1944,7 @@ namespace qobject {
{
Sender sender;
Receiver receiver;
QObject::connect(&sender, SIGNAL(aSignal()), &receiver, SLOT(aSlot()));
QObject::connect(&sender, &Sender::aSignal, &receiver, &Receiver::aSlot);
// Break here.
// Single step through signal emission.
sender.doEmit();

View File

@@ -222,8 +222,8 @@ void testObject(int &argc, char *argv[])
QObject ob1;
ob1.setObjectName("Another Object");
QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));
QObject::connect(&app, SIGNAL(lastWindowClosed()), &ob, SLOT(deleteLater()));
QObject::connect(&ob, &QObject::destroyed, &ob1, &QObject::deleteLater);
QObject::connect(&app, &QGuiApplication::lastWindowClosed, &ob, &QObject::deleteLater);
QList<QObject *> obs;
obs.append(&ob);

View File

@@ -222,8 +222,8 @@ void testObject(int &argc, char *argv[])
QObject ob1;
ob1.setObjectName("Another Object");
QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));
QObject::connect(&app, SIGNAL(lastWindowClosed()), &ob, SLOT(deleteLater()));
QObject::connect(&ob, &QObject::destroyed, &ob1, &QObject::deleteLater);
QObject::connect(&app, &QGuiApplication::lastWindowClosed, &ob, &QObject::deleteLater);
QList<QObject *> obs;
obs.append(&ob);

View File

@@ -84,7 +84,6 @@ public:
: QObject(parent), m_widget(widget), m_mainWindow(mw)
{}
public slots:
void changeSelection(const QList<QTextEdit::ExtraSelection> &s)
{
if (QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget))
@@ -230,19 +229,18 @@ void readFile(FakeVimHandler &handler, const QString &editFileName)
void connectSignals(FakeVimHandler &handler, Proxy &proxy)
{
QObject::connect(&handler, SIGNAL(commandBufferChanged(QString,int,int,int,QObject*)),
&proxy, SLOT(changeStatusMessage(QString,int)));
QObject::connect(&handler,
SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)),
&proxy, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>)));
QObject::connect(&handler, SIGNAL(extraInformationChanged(QString)),
&proxy, SLOT(changeExtraInformation(QString)));
QObject::connect(&handler, SIGNAL(statusDataChanged(QString)),
&proxy, SLOT(changeStatusData(QString)));
QObject::connect(&handler, SIGNAL(highlightMatches(QString)),
&proxy, SLOT(highlightMatches(QString)));
QObject::connect(&handler, SIGNAL(handleExCommandRequested(bool*,ExCommand)),
&proxy, SLOT(handleExCommand(bool*,ExCommand)));
QObject::connect(&handler, &FakeVimHandler::commandBufferChanged,
&proxy, &Proxy::changeStatusMessage);
QObject::connect(&handler, &FakeVimHandler::selectionChanged,
&proxy, &Proxy::changeSelection);
QObject::connect(&handler, &FakeVimHandler::extraInformationChanged,
&proxy, &Proxy::changeExtraInformation);
QObject::connect(&handler, &FakeVimHandler::statusDataChanged,
&proxy, &Proxy::changeStatusData);
QObject::connect(&handler, &FakeVimHandler::highlightMatches,
&proxy, &Proxy::highlightMatches);
QObject::connect(&handler, &FakeVimHandler::handleExCommandRequested,
&proxy, &Proxy::handleExCommand);
}
int main(int argc, char *argv[])

View File

@@ -38,12 +38,11 @@ class PluginDialog : public QWidget
public:
PluginDialog();
private slots:
private:
void updateButtons();
void openDetails(ExtensionSystem::PluginSpec *spec = nullptr);
void openErrorDetails();
private:
ExtensionSystem::PluginView *m_view;
QPushButton *m_detailsButton;

View File

@@ -37,7 +37,7 @@ MainWindow::MainWindow(QWidget *parent) :
m_logWindow(new QPlainTextEdit)
{
setCentralWidget(m_logWindow);
QTimer::singleShot(200, this, SLOT(test()));
QTimer::singleShot(200, this, &MainWindow::test);
}
void MainWindow::append(const QString &s)
@@ -54,8 +54,8 @@ void MainWindow::test()
Utils::SynchronousProcess process;
process.setTimeoutS(2);
qDebug() << "Async: " << cmd << args;
connect(&process, SIGNAL(stdOut(QString,bool)), this, SLOT(append(QString)));
connect(&process, SIGNAL(stdErr(QString,bool)), this, SLOT(append(QString)));
connect(&process, &Utils::SynchronousProcess::stdOut, this, &MainWindow::append);
connect(&process, &Utils::SynchronousProcess::stdErr, this, &MainWindow::append);
const Utils::SynchronousProcessResponse resp = process.run(cmd, args);
qDebug() << resp;
}

View File

@@ -37,9 +37,6 @@ Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
signals:
public slots:
void test();
void append(const QString &s);

View File

@@ -110,7 +110,7 @@ public:
delete m_connection;
}
private slots:
private:
void handleConnected()
{
qDebug("Error: Received unexpected connected() signal.");
@@ -162,7 +162,6 @@ private slots:
qDebug("Error: The following test timed out: %s", testItem.description);
}
private:
void runNextTest()
{
if (m_connection) {
@@ -170,10 +169,10 @@ private:
delete m_connection;
}
m_connection = new SshConnection(m_testSet.first().params);
connect(m_connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
connect(m_connection, SIGNAL(dataAvailable(QString)), SLOT(handleDataAvailable(QString)));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleError(QSsh::SshError)));
connect(m_connection, &SshConnection::connected, this, &Test::handleConnected);
connect(m_connection, &SshConnection::disconnected, this, &Test::handleDisconnected);
connect(m_connection, &SshConnection::dataAvailable, this, &Test::handleDataAvailable);
connect(m_connection, &SshConnection::error, this, &Test::handleError);
const TestItem &nextItem = m_testSet.first();
m_timeoutTimer.stop();
m_timeoutTimer.setInterval(qMax(10000, nextItem.params.timeout * 1000));

View File

@@ -45,7 +45,7 @@ RemoteProcessTest::RemoteProcessTest(const SshConnectionParameters &params)
m_state(Inactive)
{
m_timeoutTimer->setInterval(5000);
connect(m_timeoutTimer, SIGNAL(timeout()), SLOT(handleTimeout()));
connect(m_timeoutTimer, &QTimer::timeout, this, &RemoteProcessTest::handleTimeout);
}
RemoteProcessTest::~RemoteProcessTest()
@@ -55,14 +55,16 @@ RemoteProcessTest::~RemoteProcessTest()
void RemoteProcessTest::run()
{
connect(m_remoteRunner, SIGNAL(connectionError()),
SLOT(handleConnectionError()));
connect(m_remoteRunner, SIGNAL(processStarted()),
SLOT(handleProcessStarted()));
connect(m_remoteRunner, SIGNAL(readyReadStandardOutput()), SLOT(handleProcessStdout()));
connect(m_remoteRunner, SIGNAL(readyReadStandardError()), SLOT(handleProcessStderr()));
connect(m_remoteRunner, SIGNAL(processClosed(int)),
SLOT(handleProcessClosed(int)));
connect(m_remoteRunner, &SshRemoteProcessRunner::connectionError,
this, &RemoteProcessTest::handleConnectionError);
connect(m_remoteRunner, &SshRemoteProcessRunner::processStarted,
this, &RemoteProcessTest::handleProcessStarted);
connect(m_remoteRunner, &SshRemoteProcessRunner::readyReadStandardOutput,
this, &RemoteProcessTest::handleProcessStdout);
connect(m_remoteRunner, &SshRemoteProcessRunner::readyReadStandardError,
this, &RemoteProcessTest::handleProcessStderr);
connect(m_remoteRunner, &SshRemoteProcessRunner::processClosed,
this, &RemoteProcessTest::handleProcessClosed);
std::cout << "Testing successful remote process... " << std::flush;
m_state = TestingSuccess;
@@ -91,7 +93,8 @@ void RemoteProcessTest::handleProcessStarted()
SshRemoteProcessRunner * const killer = new SshRemoteProcessRunner(this);
killer->run("pkill -9 sleep", m_sshParams);
} else if (m_state == TestingIoDevice) {
connect(m_catProcess.data(), SIGNAL(readyRead()), SLOT(handleReadyRead()));
connect(m_catProcess.data(), &QIODevice::readyRead,
this, &RemoteProcessTest::handleReadyRead);
m_textStream = new QTextStream(m_catProcess.data());
*m_textStream << testString();
m_textStream->flush();
@@ -209,9 +212,10 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
std::cout << "Ok.\nTesting I/O device functionality... " << std::flush;
m_state = TestingIoDevice;
m_sshConnection = new SshConnection(m_sshParams);
connect(m_sshConnection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_sshConnection, SIGNAL(error(QSsh::SshError)),
SLOT(handleConnectionError()));
connect(m_sshConnection, &SshConnection::connected,
this, &RemoteProcessTest::handleConnected);
connect(m_sshConnection, &SshConnection::error,
this, &RemoteProcessTest::handleConnectionError);
m_sshConnection->connectToHost();
m_timeoutTimer->start();
break;
@@ -280,8 +284,10 @@ void RemoteProcessTest::handleConnected()
Q_ASSERT(m_state == TestingIoDevice);
m_catProcess = m_sshConnection->createRemoteProcess(QString::fromLatin1("/bin/cat").toUtf8());
connect(m_catProcess.data(), SIGNAL(started()), SLOT(handleProcessStarted()));
connect(m_catProcess.data(), SIGNAL(closed(int)), SLOT(handleProcessClosed(int)));
connect(m_catProcess.data(), &SshRemoteProcess::started,
this, &RemoteProcessTest::handleProcessStarted);
connect(m_catProcess.data(), &SshRemoteProcess::closed,
this, &RemoteProcessTest::handleProcessClosed);
m_started = false;
m_timeoutTimer->start();
m_catProcess->start();
@@ -347,11 +353,14 @@ void RemoteProcessTest::handleSuccessfulIoTest()
m_remoteStderr.clear();
m_echoProcess = m_sshConnection->createRemoteProcess("printf " + StderrOutput + " >&2");
m_echoProcess->setReadChannel(QProcess::StandardError);
connect(m_echoProcess.data(), SIGNAL(started()), SLOT(handleProcessStarted()));
connect(m_echoProcess.data(), SIGNAL(closed(int)), SLOT(handleProcessClosed(int)));
connect(m_echoProcess.data(), SIGNAL(readyRead()), SLOT(handleReadyRead()));
connect(m_echoProcess.data(), SIGNAL(readyReadStandardError()),
SLOT(handleReadyReadStderr()));
connect(m_echoProcess.data(), &SshRemoteProcess::started,
this, &RemoteProcessTest::handleProcessStarted);
connect(m_echoProcess.data(), &SshRemoteProcess::closed,
this, &RemoteProcessTest::handleProcessClosed);
connect(m_echoProcess.data(), &QIODevice::readyRead,
this, &RemoteProcessTest::handleReadyRead);
connect(m_echoProcess.data(), &SshRemoteProcess::readyReadStandardError,
this, &RemoteProcessTest::handleReadyReadStderr);
m_echoProcess->start();
m_timeoutTimer->start();
}

View File

@@ -40,7 +40,12 @@ public:
~RemoteProcessTest();
void run();
private slots:
private:
enum State {
Inactive, TestingSuccess, TestingFailure, TestingCrash, TestingTerminal, TestingIoDevice,
TestingProcessChannels
};
void handleConnectionError();
void handleProcessStarted();
void handleProcessStdout();
@@ -52,12 +57,6 @@ private slots:
void handleReadyReadStderr();
void handleConnected();
private:
enum State {
Inactive, TestingSuccess, TestingFailure, TestingCrash, TestingTerminal, TestingIoDevice,
TestingProcessChannels
};
QString testString() const;
void handleSuccessfulCrashTest();
void handleSuccessfulIoTest();

View File

@@ -56,9 +56,9 @@ SftpTest::~SftpTest()
void SftpTest::run()
{
m_connection = new SshConnection(m_parameters.sshParams);
connect(m_connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleError()));
connect(m_connection, SIGNAL(disconnected()), SLOT(handleDisconnected()));
connect(m_connection, &SshConnection::connected, this, &SftpTest::handleConnected);
connect(m_connection, &SshConnection::error, this, &SftpTest::handleError);
connect(m_connection, &SshConnection::disconnected, this, &SftpTest::handleDisconnected);
std::cout << "Connecting to host '"
<< qPrintable(m_parameters.sshParams.host) << "'..." << std::endl;
m_state = Connecting;
@@ -74,17 +74,17 @@ void SftpTest::handleConnected()
} else {
std::cout << "Connected. Initializing SFTP channel..." << std::endl;
m_channel = m_connection->createSftpChannel();
connect(m_channel.data(), SIGNAL(initialized()), this,
SLOT(handleChannelInitialized()));
connect(m_channel.data(), SIGNAL(channelError(QString)), this,
SLOT(handleChannelInitializationFailure(QString)));
connect(m_channel.data(), SIGNAL(finished(QSsh::SftpJobId,QString)),
this, SLOT(handleJobFinished(QSsh::SftpJobId,QString)));
connect(m_channel.data(),
SIGNAL(fileInfoAvailable(QSsh::SftpJobId,QList<QSsh::SftpFileInfo>)),
SLOT(handleFileInfo(QSsh::SftpJobId,QList<QSsh::SftpFileInfo>)));
connect(m_channel.data(), SIGNAL(closed()), this,
SLOT(handleChannelClosed()));
connect(m_channel.data(), &SftpChannel::initialized,
this, &SftpTest::handleChannelInitialized);
connect(m_channel.data(), &SftpChannel::channelError,
this, &SftpTest::handleChannelInitializationFailure);
connect(m_channel.data(), &SftpChannel::finished,
this, static_cast<void (SftpTest::*)(QSsh::SftpJobId, const QString &)>(
&SftpTest::handleJobFinished));
connect(m_channel.data(), &SftpChannel::fileInfoAvailable,
this, &SftpTest::handleFileInfo);
connect(m_channel.data(), &SftpChannel::closed,
this, &SftpTest::handleChannelClosed);
m_state = InitializingChannel;
m_channel->initialize();
}

View File

@@ -46,16 +46,6 @@ public:
~SftpTest();
void run();
private slots:
void handleConnected();
void handleError();
void handleDisconnected();
void handleChannelInitialized();
void handleChannelInitializationFailure(const QString &reason);
void handleJobFinished(QSsh::SftpJobId job, const QString &error);
void handleFileInfo(QSsh::SftpJobId job, const QList<QSsh::SftpFileInfo> &fileInfoList);
void handleChannelClosed();
private:
typedef QHash<QSsh::SftpJobId, QString> JobMap;
typedef QSharedPointer<QFile> FilePtr;
@@ -65,6 +55,15 @@ private:
CheckingDirAttributes, CheckingDirContents, RemovingDir, ChannelClosing, Disconnecting
};
void handleConnected();
void handleError();
void handleDisconnected();
void handleChannelInitialized();
void handleChannelInitializationFailure(const QString &reason);
void handleJobFinished(QSsh::SftpJobId job, const QString &error);
void handleFileInfo(QSsh::SftpJobId job, const QList<QSsh::SftpFileInfo> &fileInfoList);
void handleChannelClosed();
void removeFile(const FilePtr &filePtr, bool remoteToo);
void removeFiles(bool remoteToo);
QString cmpFileName(const QString &localFileName) const;

View File

@@ -44,8 +44,8 @@ using namespace QSsh;
SftpFsWindow::SftpFsWindow(QWidget *parent) : QDialog(parent), m_ui(new Ui::Window)
{
m_ui->setupUi(this);
connect(m_ui->connectButton, SIGNAL(clicked()), SLOT(connectToHost()));
connect(m_ui->downloadButton, SIGNAL(clicked()), SLOT(downloadFile()));
connect(m_ui->connectButton, &QAbstractButton::clicked, this, &SftpFsWindow::connectToHost);
connect(m_ui->downloadButton, &QAbstractButton::clicked, this, &SftpFsWindow::downloadFile);
}
SftpFsWindow::~SftpFsWindow()
@@ -67,11 +67,12 @@ void SftpFsWindow::connectToHost()
m_fsModel = new SftpFileSystemModel(this);
if (m_ui->useModelTesterCheckBox->isChecked())
new ModelTest(m_fsModel, this);
connect(m_fsModel, SIGNAL(sftpOperationFailed(QString)),
SLOT(handleSftpOperationFailed(QString)));
connect(m_fsModel, SIGNAL(connectionError(QString)), SLOT(handleConnectionError(QString)));
connect(m_fsModel, SIGNAL(sftpOperationFinished(QSsh::SftpJobId,QString)),
SLOT(handleSftpOperationFinished(QSsh::SftpJobId,QString)));
connect(m_fsModel, &SftpFileSystemModel::sftpOperationFailed,
this, &SftpFsWindow::handleSftpOperationFailed);
connect(m_fsModel, &SftpFileSystemModel::connectionError,
this, &SftpFsWindow::handleConnectionError);
connect(m_fsModel, &SftpFileSystemModel::sftpOperationFinished,
this, &SftpFsWindow::handleSftpOperationFinished);
m_fsModel->setSshConnection(sshParams);
m_ui->fsView->setModel(m_fsModel);
}

View File

@@ -40,14 +40,13 @@ public:
SftpFsWindow(QWidget *parent = 0);
~SftpFsWindow();
private slots:
private:
void connectToHost();
void downloadFile();
void handleConnectionError(const QString &errorMessage);
void handleSftpOperationFailed(const QString &errorMessage);
void handleSftpOperationFinished(QSsh::SftpJobId jobId, const QString &error);
private:
QSsh::SftpFileSystemModel *m_fsModel;
Ui::Window *m_ui;
};

View File

@@ -42,9 +42,9 @@ Shell::Shell(const SshConnectionParameters &parameters, QObject *parent)
m_connection(new SshConnection(parameters)),
m_stdin(new QFile(this))
{
connect(m_connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_connection, SIGNAL(dataAvailable(QString)), SLOT(handleShellMessage(QString)));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
connect(m_connection, &SshConnection::connected, this, &Shell::handleConnected);
connect(m_connection, &SshConnection::dataAvailable, this, &Shell::handleShellMessage);
connect(m_connection, &SshConnection::error, this, &Shell::handleConnectionError);
}
Shell::~Shell()
@@ -77,17 +77,19 @@ void Shell::handleShellMessage(const QString &message)
void Shell::handleConnected()
{
m_shell = m_connection->createRemoteShell();
connect(m_shell.data(), SIGNAL(started()), SLOT(handleShellStarted()));
connect(m_shell.data(), SIGNAL(readyReadStandardOutput()), SLOT(handleRemoteStdout()));
connect(m_shell.data(), SIGNAL(readyReadStandardError()), SLOT(handleRemoteStderr()));
connect(m_shell.data(), SIGNAL(closed(int)), SLOT(handleChannelClosed(int)));
connect(m_shell.data(), &SshRemoteProcess::started, this, &Shell::handleShellStarted);
connect(m_shell.data(), &SshRemoteProcess::readyReadStandardOutput,
this, &Shell::handleRemoteStdout);
connect(m_shell.data(), &SshRemoteProcess::readyReadStandardError,
this, &Shell::handleRemoteStderr);
connect(m_shell.data(), &SshRemoteProcess::closed, this, &Shell::handleChannelClosed);
m_shell->start();
}
void Shell::handleShellStarted()
{
QSocketNotifier * const notifier = new QSocketNotifier(0, QSocketNotifier::Read, this);
connect(notifier, SIGNAL(activated(int)), SLOT(handleStdin()));
connect(notifier, &QSocketNotifier::activated, this, &Shell::handleStdin);
}
void Shell::handleRemoteStdout()

View File

@@ -49,7 +49,7 @@ public:
void run();
private slots:
private:
void handleConnected();
void handleConnectionError();
void handleRemoteStdout();
@@ -59,7 +59,6 @@ private slots:
void handleShellStarted();
void handleStdin();
private:
QSsh::SshConnection *m_connection;
QSharedPointer<QSsh::SshRemoteProcess> m_shell;
QFile * const m_stdin;

View File

@@ -47,8 +47,8 @@ DirectTunnel::DirectTunnel(const SshConnectionParameters &parameters, QObject *p
m_targetServer(new QTcpServer(this)),
m_expectingChannelClose(false)
{
connect(m_connection, SIGNAL(connected()), SLOT(handleConnected()));
connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError()));
connect(m_connection, &SshConnection::connected, this, &DirectTunnel::handleConnected);
connect(m_connection, &SshConnection::error, this, &DirectTunnel::handleConnectionError);
}
DirectTunnel::~DirectTunnel()
@@ -77,14 +77,16 @@ void DirectTunnel::handleConnected()
return;
}
m_targetPort = m_targetServer->serverPort();
connect(m_targetServer, SIGNAL(newConnection()), SLOT(handleNewConnection()));
connect(m_targetServer, &QTcpServer::newConnection, this, &DirectTunnel::handleNewConnection);
m_tunnel = m_connection->createDirectTunnel(QLatin1String("localhost"), 1024, // made-up values
QLatin1String("localhost"), m_targetPort);
connect(m_tunnel.data(), SIGNAL(initialized()), SLOT(handleInitialized()));
connect(m_tunnel.data(), SIGNAL(error(QString)), SLOT(handleTunnelError(QString)));
connect(m_tunnel.data(), SIGNAL(readyRead()), SLOT(handleServerData()));
connect(m_tunnel.data(), SIGNAL(aboutToClose()), SLOT(handleTunnelClosed()));
connect(m_tunnel.data(), &SshDirectTcpIpTunnel::initialized,
this, &DirectTunnel::handleInitialized);
connect(m_tunnel.data(), &SshDirectTcpIpTunnel::error,
this, &DirectTunnel::handleTunnelError);
connect(m_tunnel.data(), &QIODevice::readyRead, this, &DirectTunnel::handleServerData);
connect(m_tunnel.data(), &QIODevice::aboutToClose, this, &DirectTunnel::handleTunnelClosed);
std::cout << "Initializing tunnel..." << std::endl;
m_tunnel->initialize();
@@ -95,7 +97,7 @@ void DirectTunnel::handleInitialized()
std::cout << "Writing data into the tunnel..." << std::endl;
m_tunnel->write(TestData);
QTimer * const timeoutTimer = new QTimer(this);
connect(timeoutTimer, SIGNAL(timeout()), SLOT(handleTimeout()));
connect(timeoutTimer, &QTimer::timeout, this, &DirectTunnel::handleTimeout);
timeoutTimer->start(10000);
}
@@ -131,8 +133,10 @@ void DirectTunnel::handleNewConnection()
{
m_targetSocket = m_targetServer->nextPendingConnection();
m_targetServer->close();
connect(m_targetSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(handleSocketError()));
connect(m_targetSocket, SIGNAL(readyRead()), SLOT(handleClientData()));
connect(m_targetSocket,
static_cast<void (QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error),
this, &DirectTunnel::handleSocketError);
connect(m_targetSocket, &QIODevice::readyRead, this, &DirectTunnel::handleClientData);
handleClientData();
}

View File

@@ -51,7 +51,7 @@ public:
signals:
void finished(int errorCode);
private slots:
private:
void handleConnected();
void handleConnectionError();
void handleServerData();
@@ -63,7 +63,6 @@ private slots:
void handleClientData();
void handleTimeout();
private:
QSsh::SshConnection * const m_connection;
QSharedPointer<QSsh::SshDirectTcpIpTunnel> m_tunnel;
QTcpServer * const m_targetServer;

View File

@@ -51,7 +51,7 @@ public:
signals:
void finished(int exitCode);
private slots:
private:
void handleConnected();
void handleConnectionError(QSsh::SshError error);
void handleInitialized();
@@ -60,7 +60,6 @@ private slots:
void handleNewConnection();
void handleSocketError();
private:
QSsh::SshConnection * const m_connection;
QSharedPointer<QSsh::SshTcpIpForwardServer> m_server;
QTcpSocket *m_targetSocket;