summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-12-22 13:55:43 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-01-04 13:33:39 +0000
commitfc55372413a064baa049f28a13cba1406b132cfb (patch)
treea66cf9fdc71963a21344b690a50a8fba794a4145 /tools
parent1091899a3e440d1c46716b3a6f6731bff5555dcd (diff)
downloadqtactiveqt-fc55372413a064baa049f28a13cba1406b132cfb.tar.gz
testcon: Add option to suppress installation of the message handler.
When debugging controls potentially crashing testcon, it makes sense to use the standard tools to capture debug output. Add an option and move the handler code to main.cpp. Task-number: QTBUG-49712 Change-Id: I9fd60513e7b3e6fc8a20019778a5844ad99d554e Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/testcon/main.cpp13
-rw-r--r--tools/testcon/mainwindow.cpp25
-rw-r--r--tools/testcon/mainwindow.h7
3 files changed, 30 insertions, 15 deletions
diff --git a/tools/testcon/main.cpp b/tools/testcon/main.cpp
index 56946f6..dd6dc82 100644
--- a/tools/testcon/main.cpp
+++ b/tools/testcon/main.cpp
@@ -37,6 +37,7 @@
#include <QAxFactory>
#include <QCommandLineParser>
#include <QCommandLineOption>
+#include <QDebug>
QAXFACTORY_DEFAULT(MainWindow,
QLatin1String("{5f5ce700-48a8-47b1-9b06-3b7f79e41d7c}"),
@@ -47,6 +48,12 @@ QAXFACTORY_DEFAULT(MainWindow,
QT_USE_NAMESPACE
+static void redirectDebugOutput(QtMsgType, const QMessageLogContext &, const QString &msg)
+{
+ if (MainWindow *mainWindow = MainWindow::instance())
+ mainWindow->appendLogText(msg);
+}
+
int main( int argc, char **argv )
{
QApplication app( argc, argv );
@@ -61,10 +68,16 @@ int main( int argc, char **argv )
QLatin1String("A script to load."),
QLatin1String("script"));
parser.addOption(scriptOption);
+ QCommandLineOption noMessageHandlerOption(QLatin1String("no-messagehandler"),
+ QLatin1String("Suppress installation of the message handler."));
+ parser.addOption(noMessageHandlerOption);
parser.addPositionalArgument(QLatin1String("clsid/file"),
QLatin1String("The clsid/file to show."));
parser.process(app);
+ if (!parser.isSet(noMessageHandlerOption))
+ qInstallMessageHandler(redirectDebugOutput);
+
MainWindow mw;
foreach (const QString &a, parser.positionalArguments()) {
if (a.startsWith(QLatin1Char('{')) && a.endsWith(QLatin1Char('}')))
diff --git a/tools/testcon/mainwindow.cpp b/tools/testcon/mainwindow.cpp
index 826912e..e4587be 100644
--- a/tools/testcon/mainwindow.cpp
+++ b/tools/testcon/mainwindow.cpp
@@ -53,16 +53,6 @@
QT_BEGIN_NAMESPACE
-QAxObject *ax_mainWindow = 0;
-
-static QTextEdit *debuglog = 0;
-
-static void redirectDebugOutput(QtMsgType type, const QMessageLogContext &, const QString &msg)
-{
- Q_UNUSED(type);
- debuglog->append(msg);
-}
-
QT_END_NAMESPACE
QT_USE_NAMESPACE
@@ -77,6 +67,8 @@ static const ScriptLanguage scriptLanguages[] = {
{"Python", ".py"}
};
+MainWindow *MainWindow::m_instance = Q_NULLPTR;
+
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, m_dlgInvoke(Q_NULLPTR)
@@ -84,12 +76,11 @@ MainWindow::MainWindow(QWidget *parent)
, m_dlgAmbient(Q_NULLPTR)
, m_scripts(Q_NULLPTR)
{
+ MainWindow::m_instance = this;
+
setupUi(this);
setObjectName(QLatin1String("MainWindow"));
- debuglog = logDebug;
- m_oldDebugHandler = qInstallMessageHandler(redirectDebugOutput);
-
const int scriptCount = int(sizeof(scriptLanguages) / sizeof(scriptLanguages[0]));
for (int s = 0; s < scriptCount; ++s) {
const QString name = QLatin1String(scriptLanguages[s].name);
@@ -110,8 +101,7 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
- qInstallMessageHandler(m_oldDebugHandler);
- debuglog = 0;
+ MainWindow::m_instance = Q_NULLPTR;
}
QAxWidget *MainWindow::activeAxWidget() const
@@ -156,6 +146,11 @@ void MainWindow::closeEvent(QCloseEvent *e)
e->accept();
}
+void MainWindow::appendLogText(const QString &message)
+{
+ logDebug->append(message);
+}
+
void MainWindow::on_actionFileNew_triggered()
{
QAxSelect select(this);
diff --git a/tools/testcon/mainwindow.h b/tools/testcon/mainwindow.h
index af5454d..a9d15dd 100644
--- a/tools/testcon/mainwindow.h
+++ b/tools/testcon/mainwindow.h
@@ -57,6 +57,8 @@ public:
MainWindow(QWidget *parent = 0);
~MainWindow();
+ static MainWindow *instance() { return m_instance; }
+
bool addControlFromClsid(const QString &clsid);
bool addControlFromFile(const QString &fileName);
bool loadScript(const QString &file);
@@ -64,6 +66,9 @@ public:
protected:
void closeEvent(QCloseEvent *) Q_DECL_OVERRIDE;
+public slots:
+ void appendLogText(const QString &);
+
protected slots:
void on_actionFileNew_triggered();
void on_actionFileLoad_triggered();
@@ -87,6 +92,8 @@ private:
QAxWidget *activeAxWidget() const;
QList<QAxWidget *> axWidgets() const;
+ static MainWindow *m_instance;
+
InvokeMethod *m_dlgInvoke;
ChangeProperties *m_dlgProperties;
AmbientProperties *m_dlgAmbient;