examples: Remove shell example
We did not document it anywhere, the code is rather dated, and if we want to promote QML as a scripting engine/an interpreter, we would need to invest quite a bit more effort into a showcase. Thus, remove the example for now. Pick-to: 6.5 Task-number: QTBUG-110649 Change-Id: Ie23b26379e7ea72271d793a6928a3757cde2cb12 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
17d0bf258b
commit
e0c4a5ecf9
|
@ -3,7 +3,6 @@
|
|||
|
||||
add_subdirectory(referenceexamples)
|
||||
add_subdirectory(tutorials)
|
||||
qt_internal_add_example(shell)
|
||||
if(TARGET Qt::Quick)
|
||||
qt_internal_add_example(qmlextensionplugins)
|
||||
if (TARGET Qt::lupdate)
|
||||
|
|
|
@ -8,8 +8,7 @@ qtHaveModule(quick) {
|
|||
|
||||
SUBDIRS += \
|
||||
referenceexamples \
|
||||
tutorials \
|
||||
shell
|
||||
tutorials
|
||||
|
||||
EXAMPLE_FILES = \
|
||||
dynamicscene \
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(shell LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/shell")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Qml)
|
||||
|
||||
qt_add_executable(shell
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(shell PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(shell PUBLIC
|
||||
Qt::Core
|
||||
Qt::Qml
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set_target_properties(shell PROPERTIES
|
||||
WIN32_EXECUTABLE FALSE
|
||||
)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set_target_properties(shell PROPERTIES
|
||||
MACOSX_BUNDLE FALSE
|
||||
)
|
||||
endif()
|
||||
|
||||
install(TARGETS shell
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
|
@ -1,116 +0,0 @@
|
|||
// Copyright (C) 2017 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
|
||||
#include <QtCore/qfile.h>
|
||||
#include <QtCore/qtextstream.h>
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/qscopedpointer.h>
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
#include <QtQml/qjsengine.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
class CommandInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_INVOKABLE void quit() { m_wantsToQuit = true; }
|
||||
static bool wantsToQuit() { return m_wantsToQuit; }
|
||||
private:
|
||||
static bool m_wantsToQuit;
|
||||
};
|
||||
|
||||
bool CommandInterface::m_wantsToQuit = false;
|
||||
|
||||
|
||||
static void interactive(QJSEngine *eng)
|
||||
{
|
||||
QTextStream qin(stdin, QFile::ReadOnly);
|
||||
const char *prompt = "qs> ";
|
||||
|
||||
forever {
|
||||
QString line;
|
||||
|
||||
printf("%s", prompt);
|
||||
fflush(stdout);
|
||||
|
||||
line = qin.readLine();
|
||||
if (line.isNull())
|
||||
break;
|
||||
|
||||
if (line.trimmed().isEmpty())
|
||||
continue;
|
||||
|
||||
line += QLatin1Char('\n');
|
||||
|
||||
QJSValue result = eng->evaluate(line, QLatin1String("typein"));
|
||||
|
||||
fprintf(stderr, "%s\n", qPrintable(result.toString()));
|
||||
|
||||
if (CommandInterface::wantsToQuit())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
QScopedPointer<QJSEngine> eng(new QJSEngine());
|
||||
{
|
||||
QJSValue globalObject = eng->globalObject();
|
||||
QJSValue interface = eng->newQObject(new CommandInterface);
|
||||
globalObject.setProperty("qt", interface);
|
||||
}
|
||||
|
||||
if (! *++argv) {
|
||||
interactive(eng.data());
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
while (const char *arg = *argv++) {
|
||||
QString fileName = QString::fromLocal8Bit(arg);
|
||||
|
||||
if (fileName == QLatin1String("-i")) {
|
||||
interactive(eng.data());
|
||||
break;
|
||||
}
|
||||
|
||||
QString contents;
|
||||
int lineNumber = 1;
|
||||
|
||||
if (fileName == QLatin1String("-")) {
|
||||
QTextStream stream(stdin, QFile::ReadOnly);
|
||||
contents = stream.readAll();
|
||||
} else {
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QTextStream stream(&file);
|
||||
contents = stream.readAll();
|
||||
file.close();
|
||||
|
||||
// strip off #!/usr/bin/env qjs line
|
||||
if (contents.startsWith("#!")) {
|
||||
contents.remove(0, contents.indexOf("\n"));
|
||||
++lineNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (contents.isEmpty())
|
||||
continue;
|
||||
|
||||
QJSValue result = eng->evaluate(contents, fileName, lineNumber);
|
||||
if (result.isError()) {
|
||||
fprintf (stderr, " %s\n\n", qPrintable(result.toString()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#include <main.moc>
|
|
@ -1,9 +0,0 @@
|
|||
QT = core qml
|
||||
|
||||
win32: CONFIG += console
|
||||
mac:CONFIG -= app_bundle
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/qml/shell
|
||||
INSTALLS += target
|
Loading…
Reference in New Issue