Просмотр исходного кода

readme and simple example added

Reinhard Russinger 8 лет назад
Родитель
Сommit
0714578906

+ 59 - 0
README.md

@@ -0,0 +1,59 @@
+### Application Launcher
+
+App Launcher plugin for QT Qml 
+
+    
+```qml
+
+import ApplicationLauncher 1.0
+
+.....
+
+    Application {
+        id: testScripts
+        appName: "cat"
+        arguments: "/etc/passwd"
+
+        onAppFinished: {
+            console.debug("AppFinished :");
+            console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
+            console.debug("stdERR :" + stdERR);
+            console.debug("stdOUT :" + stdOUT);
+        }
+
+        onAppStarted: {
+            console.debug("appStarted :");
+            console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
+
+        }
+
+        onAppError: {
+            console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
+
+        }
+    }
+
+......
+
+```
+
+- **Properties**
+	-- appName : Executeable (with or without parameters!)
+	-- arguments : arguments if not given with appName
+	-- stdERR : output of stderr as QString
+	-- stdOUT : output as QString
+	-- exitError
+	-- exitStatus
+	-- exitCode
+
+- **Events**
+	-- onAppFinished : app has ended properties are available
+	-- onAppStarted : app has started
+	-- onAppError : error on start or in app
+
+- **Methods**
+	-- launchScript() : start application (is started async and not in main event queue)
+
+
+
+    

+ 46 - 3
application.cpp

@@ -8,6 +8,14 @@ Application::Application(QObject *parent) :
     connect(m_process,
                SIGNAL(finished(int, QProcess::ExitStatus)),
                SLOT(finished(int, QProcess::ExitStatus)));
+
+    connect(m_process,
+            SIGNAL(started()),
+            SLOT(process_started()));
+
+    connect(m_process,
+            SIGNAL(errorOccurred(QProcess::ProcessError)),
+            SLOT(process_error(QProcess::ProcessError)));
 }
 
 QString Application::appName() const
@@ -40,6 +48,20 @@ void Application::setstdOUT(const QString &stdOUT)
     m_stdOUT = stdOUT;
 }
 
+int Application::exitCode()
+{
+    return m_exitCode;
+}
+
+int Application::exitStatus()
+{
+    return m_exitStatus;
+}
+
+int Application::exitError()
+{
+    return m_error;
+}
 
 QString Application::arguments() const
 {
@@ -51,16 +73,37 @@ void Application::setArguments(const QString &arguments)
     m_Arguments = arguments;
 }
 
-QString Application::launchScriptGetSTDOUT()
+void Application::launchScript()
 {
+    m_stdERR.clear();
+    m_stdOUT.clear();
+    m_exitCode = -1;
+    m_exitStatus = -1;
+    m_error = -1;
+
     m_process->start(m_AppName + " " +  m_Arguments);
-//    m_process->waitForStarted(-1);
-    return "Start requested";
     qDebug() << "launching application" << m_AppName << "\n with the Argument of \n" + m_Arguments  ;
 }
+
+
 void Application::finished(int exitCode, QProcess::ExitStatus status)
 {
     m_stdOUT = QString(m_process->readAllStandardOutput());
     m_stdERR = QString(m_process->readAllStandardError());
+    m_exitCode = exitCode;
+    m_exitStatus = status;
+
     emit this->appFinished();
 }
+
+void Application::process_started(void)
+{
+    emit this->appStarted();
+}
+
+
+void Application::process_error(QProcess::ProcessError app_error)
+{
+    m_error = app_error;
+    emit this->appError();
+}

+ 24 - 5
application.h

@@ -8,10 +8,20 @@ class Application : public QObject
 
 public:
     explicit Application(QObject *parent = 0);
-    Q_PROPERTY( QString         appName                 READ appName                 WRITE setAppName                 )
-    Q_PROPERTY( QString         arguments                 READ arguments                 WRITE setArguments                 )
-    Q_PROPERTY( QString         stdERR                 READ stdERR                 WRITE setstdERR                 )
-    Q_PROPERTY( QString         stdOUT                 READ stdOUT                 WRITE setstdOUT                 )
+    Q_PROPERTY( QString appName READ appName WRITE setAppName)
+    Q_PROPERTY( QString arguments READ arguments WRITE setArguments)
+    Q_PROPERTY( QString stdERR READ stdERR  WRITE setstdERR)
+    Q_PROPERTY( QString stdOUT READ stdOUT WRITE setstdOUT)
+
+    Q_PROPERTY( int exitCode READ exitCode)
+    int exitCode();
+
+    Q_PROPERTY( int exitStatus READ exitStatus)
+    int exitStatus();
+
+    Q_PROPERTY( int exitError READ exitError)
+    int exitError();
+
 
     QString appName() const;
     void setAppName(const QString &appName);
@@ -21,11 +31,13 @@ public:
     void setstdERR(const QString &stdERR);
     QString stdOUT() const;
     void setstdOUT(const QString &stdOUT);
+
     Q_INVOKABLE void launchScript();
-    Q_INVOKABLE QString launchScriptGetSTDOUT();
 
  Q_SIGNALS:
     void appFinished();
+    void appStarted();
+    void appError();
 
 private:
     QProcess *m_process;
@@ -33,8 +45,15 @@ private:
     QString m_Arguments;
     QString m_stdERR;
     QString m_stdOUT;
+    int m_exitCode;
+    int m_exitStatus;
+    int m_error;
+
 
 private Q_SLOTS:
     void finished(int exitCode, QProcess::ExitStatus status);
+    void process_started(void);
+    void process_error(QProcess::ProcessError);
+
 };
 #endif //APPLICATION_H

+ 7 - 1
applicationlauncher.pro

@@ -28,7 +28,13 @@ OTHER_FILES = qmldir
 }
 
 qmldir.files = qmldir
-unix {
+
+linux-buildroot-g++ {
+    installPath = /usr/qml/$$replace(uri, \\., /)
+    qmldir.path = $$installPath
+    target.path = $$installPath
+    INSTALLS += target qmldir
+} else {
     installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
     qmldir.path = $$installPath
     target.path = $$installPath

+ 73 - 0
example/AppTest/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 29 - 0
example/AppTest/AppTest.pro

@@ -0,0 +1,29 @@
+QT += qml quick
+
+CONFIG += c++11
+
+SOURCES += main.cpp
+
+RESOURCES += qml.qrc
+
+# Additional import path used to resolve QML modules in Qt Creator's code model
+QML_IMPORT_PATH =
+
+# Additional import path used to resolve QML modules just for Qt Quick Designer
+QML_DESIGNER_IMPORT_PATH =
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target

+ 13 - 0
example/AppTest/main.cpp

@@ -0,0 +1,13 @@
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+    QGuiApplication app(argc, argv);
+
+    QQmlApplicationEngine engine;
+    engine.load(QUrl(QLatin1String("qrc:/main.qml")));
+
+    return app.exec();
+}

+ 48 - 0
example/AppTest/main.qml

@@ -0,0 +1,48 @@
+import QtQuick 2.5
+import QtQuick.Controls 1.4
+import QtQuick.Layouts 1.0
+import ApplicationLauncher 1.0
+
+ApplicationWindow {
+    visible: true
+    width: 640
+    height: 480
+    title: qsTr("Hello World")
+
+    Application {
+        id: testScripts
+        appName: "cat"
+        arguments: "/etc/passwd"
+
+        onAppFinished: {
+            console.debug("AppFinished :");
+            console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
+            console.debug("stdERR :" + stdERR);
+            console.debug("stdOUT :" + stdOUT);
+        }
+
+        onAppStarted: {
+            console.debug("appStarted :");
+            console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
+
+        }
+
+        onAppError: {
+            console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
+
+        }
+    }
+
+    Button {
+        x:10
+        y:10
+        height: 40
+        width:120
+        text: "apptest"
+        onClicked: {
+            testScripts.launchScript();
+        }
+    }
+
+
+}

+ 5 - 0
example/AppTest/qml.qrc

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>main.qml</file>
+    </qresource>
+</RCC>