Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmldebugconsole_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#ifndef QQMLDEBUGCONSOLE_P_H
6#define QQMLDEBUGCONSOLE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qobject.h>
20#include <QtCore/qstringlist.h>
21#include <QtCore/qthread.h>
22
23#include <functional>
24
25QT_BEGIN_NAMESPACE
26
27class QQmlDebugCommandListener;
28
29// A simple interactive command line for QML debugging tools. It reads commands
30// from standard input on a worker thread, dispatches them to registered
31// handlers, and provides a reusable yes/no confirmation flow. Both qmlprofiler
32// and qmlpreview drive their interactive modes through this class.
34{
36public:
37 using CommandHandler = std::function<void(const QStringList &args)>;
38
39 explicit QQmlDebugConsole(QObject *parent = nullptr);
41
42 void registerCommand(const QStringList &names, const QString &argsHint,
43 const QString &description, CommandHandler handler);
44
45 void start();
46 void stop();
47
48 void prompt(const QString &message = QString(), bool ready = true);
49 void printLine(const QString &message);
50
51 void askConfirmation(const QString &question, std::function<void()> onConfirmed,
52 std::function<void()> onDeclined = {});
53
56 // Emitted when standard input is closed (EOF). Consumers typically quit.
57 void endOfInput();
58
59private:
60 struct Command
61 {
62 QStringList names;
63 QString argsHint;
64 QString description;
65 CommandHandler handler;
66 };
67
68 void handleLine(const QString &line);
69 void printHelp();
70
71 QThread m_listenerThread;
72 QQmlDebugCommandListener *m_listener = nullptr;
73
74 QList<Command> m_commands;
75
76 QString m_pendingQuestion;
77 std::function<void()> m_onConfirmed;
78 std::function<void()> m_onDeclined;
79};
80
81QT_END_NAMESPACE
82
83#endif // QQMLDEBUGCONSOLE_P_H
void askConfirmation(const QString &question, std::function< void()> onConfirmed, std::function< void()> onDeclined={})
QQmlDebugConsole(QObject *parent=nullptr)
void printLine(const QString &message)
void registerCommand(const QStringList &names, const QString &argsHint, const QString &description, CommandHandler handler)
void prompt(const QString &message=QString(), bool ready=true)