Exemple #1
0
        public void Can_put_and_get_env()
        {
            var envName = Guid.NewGuid().ToString().Replace("-", "");

            Qt.GetEnv(envName).Should().BeNullOrEmpty();
            Qt.PutEnv(envName, "TEST");
            Qt.GetEnv(envName).Should().Be("TEST");
            Qt.PutEnv(envName, null);
            Qt.GetEnv(envName).Should().BeNullOrEmpty();
        }
Exemple #2
0
 private static int Main(string[] args)
 {
     RuntimeManager.DiscoverOrDownloadSuitableQtRuntime();
     Qt.PutEnv("QT_QUICK_CONTROLS_CONF", System.IO.Directory.GetCurrentDirectory() + "/qml/qtquickcontrols2.conf");
     QmlNetConfig.ShouldEnsureUIThread  = false;            // remove this line when fixed in qml.net: temporary workaround for https://github.com/qmlnet/qmlnet/issues/112
     using QGuiApplication app          = new QGuiApplication(args);
     using QQmlApplicationEngine engine = new QQmlApplicationEngine();
     // Register our new type to be used in Qml
     QmlBridge.RegisterTypes();
     engine.Load(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "qml", "main.qml"));
     return(app.Exec());
 }
Exemple #3
0
 static int Main(string[] args)
 {
     Qt.PutEnv("QT_OPENGL", "angle");
     Qt.PutEnv("QT_ANGLE_PLATFORM", "warp");
     Qt.PutEnv("QT_DISABLE_SHADER_DISK_CACHE", "1");
     using (var app = new QGuiApplication(args))
     {
         using (var engine = new QQmlApplicationEngine())
         {
             Qml.Net.Qml.RegisterType <EditorModel>("Editor");
             engine.Load("main.qml");
             return(app.Exec());
         }
     }
 }
Exemple #4
0
        static int Main(string[] args)
        {
            Qt.PutEnv("QV4_MM_AGGRESSIVE_GC", "1");

            using (var app = new QGuiApplication(args))
            {
                using (var engine = new QQmlApplicationEngine())
                {
                    engine.AddImportPath(Path.Combine(Directory.GetCurrentDirectory(), "Qml"));

                    Qml.RegisterType <TestQmlImport>("test");

                    engine.Load("main.qml");

                    return(app.Exec());
                }
            }
        }
Exemple #5
0
        static Interop()
        {
            string pluginsDirectory = null;
            string qmlDirectory     = null;
            string libDirectory     = null;

            ILibraryPathResolver pathResolver = null;

            if (Host.GetExportedSymbol != null)
            {
                // We are loading exported functions from the currently running executable.
                var member = (FieldInfo)typeof(NativeLibraryBase).GetMember("PlatformLoader", BindingFlags.Static | BindingFlags.NonPublic).First();
                member.SetValue(null, new Host.Loader());
                pathResolver = new Host.Loader();
            }
            else
            {
                var internalType = Type.GetType("AdvancedDLSupport.DynamicLinkLibraryPathResolver, AdvancedDLSupport");
                if (internalType != null)
                {
                    pathResolver = (ILibraryPathResolver)Activator.CreateInstance(internalType, new object[] { true });

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        // This custom path resolver attempts to do a DllImport to get the path that .NET decides.
                        // It may load a special dll from a NuGet package.
                        pathResolver = new WindowsDllImportLibraryPathResolver(pathResolver);
                    }
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    {
                        pathResolver = new MacDllImportLibraryPathResolver(pathResolver);
                    }
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        pathResolver = new LinuxDllImportLibraryPathResolver(pathResolver);
                    }

                    var resolveResult = pathResolver.Resolve("QmlNet");

                    if (resolveResult.IsSuccess)
                    {
                        libDirectory = Path.GetDirectoryName(resolveResult.Path);
                        if (!string.IsNullOrEmpty(libDirectory))
                        {
                            // If this library has a plugins/qml directory below it, set it.
                            var potentialPlugisDirectory = Path.Combine(libDirectory, "plugins");
                            if (Directory.Exists(potentialPlugisDirectory))
                            {
                                pluginsDirectory = potentialPlugisDirectory;
                            }

                            var potentialQmlDirectory = Path.Combine(libDirectory, "qml");
                            if (Directory.Exists(potentialQmlDirectory))
                            {
                                qmlDirectory = potentialQmlDirectory;
                            }
                        }
                    }
                }
            }


            var builder = new NativeLibraryBuilder(pathResolver: pathResolver);

            var interop = builder.ActivateInterface <ICombined>("QmlNet");

            Callbacks             = interop;
            NetTypeInfo           = interop;
            NetMethodInfo         = interop;
            NetPropertyInfo       = interop;
            NetTypeManager        = interop;
            QGuiApplication       = interop;
            QQmlApplicationEngine = interop;
            NetVariant            = interop;
            NetReference          = interop;
            NetVariantList        = interop;
            NetTestHelper         = interop;
            NetSignalInfo         = interop;
            QResource             = interop;
            NetDelegate           = interop;
            NetJsValue            = interop;
            QQuickStyle           = interop;
            QtInterop             = interop;
            Utilities             = interop;
            QtWebEngine           = interop;

            if (!string.IsNullOrEmpty(pluginsDirectory))
            {
                Qt.PutEnv("QT_PLUGIN_PATH", pluginsDirectory);
            }
            if (!string.IsNullOrEmpty(qmlDirectory))
            {
                Qt.PutEnv("QML2_IMPORT_PATH", qmlDirectory);
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (!string.IsNullOrEmpty(libDirectory) && Directory.Exists(libDirectory))
                {
                    // Even though we opened up the native dll correctly, we need to add
                    // the folder to the path. The reason is because QML plugins aren't
                    // in the same directory and have trouble finding dependencies
                    // that are within our lib folder.
                    Environment.SetEnvironmentVariable("PATH",
                                                       Environment.GetEnvironmentVariable("PATH") + $";{libDirectory}");
                }
            }

            var cb = DefaultCallbacks.Callbacks();

            Callbacks.RegisterCallbacks(ref cb);
        }
Exemple #6
0
        static Interop()
        {
            IPathResolver   pathResolver = null;
            IPlatformLoader loader       = null;

            if (Host.GetExportedSymbol != null)
            {
                // We are loading exported functions from the currently running executable.
                pathResolver = new Host.Loader();
                loader       = new Host.Loader();
            }
            else
            {
                pathResolver = new DynamicLinkLibraryPathResolver();
                loader       = PlatformLoaderBase.SelectPlatformLoader();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // This custom path resolver attempts to do a DllImport to get the path that .NET decides.
                    // It may load a special dll from a NuGet package.
                    pathResolver = new WindowsDllImportLibraryPathResolver(pathResolver);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    pathResolver = new MacDllImportLibraryPathResolver(pathResolver);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    pathResolver = new LinuxDllImportLibraryPathResolver(pathResolver);
                }
            }

            var result = pathResolver.Resolve("QmlNet");

            if (!result.IsSuccess)
            {
                throw new Exception("Unable to find the native Qml.Net library." +
                                    " Try calling \"RuntimeManager.DiscoverOrDownloadSuitableQtRuntime();\" in Program.Main()");;
            }

            var library = loader.LoadLibrary(result.Path);

            if (library == IntPtr.Zero)
            {
                throw new Exception("Unable to load native Qml.Net library." +
                                    " Try calling \"RuntimeManager.DiscoverOrDownloadSuitableQtRuntime();\" in Program.Main()");;
            }

            Callbacks             = LoadInteropType <CallbacksInterop>(library, loader);
            NetTypeInfo           = LoadInteropType <NetTypeInfoInterop>(library, loader);
            NetJsValue            = LoadInteropType <NetJsValueInterop>(library, loader);
            NetMethodInfo         = LoadInteropType <NetMethodInfoInterop>(library, loader);
            NetPropertyInfo       = LoadInteropType <NetPropertyInfoInterop>(library, loader);
            NetTypeManager        = LoadInteropType <NetTypeManagerInterop>(library, loader);
            QCoreApplication      = LoadInteropType <QCoreApplicationInterop>(library, loader);
            QQmlApplicationEngine = LoadInteropType <QQmlApplicationEngineInterop>(library, loader);
            NetVariant            = LoadInteropType <NetVariantInterop>(library, loader);
            NetReference          = LoadInteropType <NetReferenceInterop>(library, loader);
            NetVariantList        = LoadInteropType <NetVariantListInterop>(library, loader);
            NetTestHelper         = LoadInteropType <NetTestHelperInterop>(library, loader);
            NetSignalInfo         = LoadInteropType <NetSignalInfoInterop>(library, loader);
            QResource             = LoadInteropType <QResourceInterop>(library, loader);
            NetDelegate           = LoadInteropType <NetDelegateInterop>(library, loader);
            QQuickStyle           = LoadInteropType <QQuickStyleInterop>(library, loader);
            QtInterop             = LoadInteropType <QtInterop>(library, loader);
            Utilities             = LoadInteropType <UtilitiesInterop>(library, loader);
            QtWebEngine           = LoadInteropType <QtWebEngineInterop>(library, loader);
            QTest      = LoadInteropType <QTestInterop>(library, loader);
            NetQObject = LoadInteropType <NetQObjectInterop>(library, loader);
            NetQObjectSignalConnection = LoadInteropType <NetQObjectSignalConnectionInterop>(library, loader);

            // RuntimeManager.ConfigureRuntimeDirectory may set these environment variables.
            // However, they only really work when called with Qt.PutEnv.
            Qt.PutEnv("QT_PLUGIN_PATH", Environment.GetEnvironmentVariable("QT_PLUGIN_PATH"));
            Qt.PutEnv("QML2_IMPORT_PATH", Environment.GetEnvironmentVariable("QML2_IMPORT_PATH"));

            var cb = DefaultCallbacks.Callbacks();

            Callbacks.RegisterCallbacks(ref cb);
        }
Exemple #7
0
        static Interop()
        {
            string pluginsDirectory = null;
            string qmlDirectory     = null;

            ILibraryPathResolver pathResolver = null;
            var internalType = Type.GetType("AdvancedDLSupport.DynamicLinkLibraryPathResolver, AdvancedDLSupport");

            if (internalType != null)
            {
                pathResolver = (ILibraryPathResolver)Activator.CreateInstance(internalType, new object[] { true });

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // This custom path resolver attempts to do a DllImport to get the path that .NET decides.
                    // It may load a special dll from a NuGet package.
                    pathResolver = new WindowsDllImportLibraryPathResolver(pathResolver);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    pathResolver = new MacDllImportLibraryPathResolver(pathResolver);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    pathResolver = new LinuxDllImportLibraryPathResolver(pathResolver);
                }

                var resolveResult = pathResolver.Resolve("QmlNet");

                if (resolveResult.IsSuccess)
                {
                    var directory = Path.GetDirectoryName(resolveResult.Path);
                    if (!string.IsNullOrEmpty(directory))
                    {
                        // If this library has a plugins/qml directory below it, set it.
                        var potentialPlugisDirectory = Path.Combine(directory, "plugins");
                        if (Directory.Exists(potentialPlugisDirectory))
                        {
                            pluginsDirectory = potentialPlugisDirectory;
                        }

                        var potentialQmlDirectory = Path.Combine(directory, "qml");
                        if (Directory.Exists(potentialQmlDirectory))
                        {
                            qmlDirectory = potentialQmlDirectory;
                        }
                    }
                }
            }


            var builder = new NativeLibraryBuilder(pathResolver: pathResolver);

            var interop = builder.ActivateInterface <ICombined>("QmlNet");

            Callbacks             = interop;
            NetTypeInfo           = interop;
            NetMethodInfo         = interop;
            NetPropertyInfo       = interop;
            NetTypeManager        = interop;
            QGuiApplication       = interop;
            QQmlApplicationEngine = interop;
            NetVariant            = interop;
            NetReference          = interop;
            NetVariantList        = interop;
            NetTestHelper         = interop;
            NetSignalInfo         = interop;
            QResource             = interop;
            NetDelegate           = interop;
            NetJsValue            = interop;
            QQuickStyle           = interop;
            QtInterop             = interop;
            Utilities             = interop;

            if (!string.IsNullOrEmpty(pluginsDirectory))
            {
                Qt.PutEnv("QT_PLUGIN_PATH", pluginsDirectory);
            }
            if (!string.IsNullOrEmpty(qmlDirectory))
            {
                Qt.PutEnv("QML2_IMPORT_PATH", qmlDirectory);
            }

            var cb = DefaultCallbacks.Callbacks();

            Callbacks.RegisterCallbacks(ref cb);
        }
Exemple #8
0
        static Interop()
        {
            string pluginsDirectory = null;
            string qmlDirectory     = null;
            string libDirectory     = null;

            IPathResolver   pathResolver = null;
            IPlatformLoader loader       = null;

            if (Host.GetExportedSymbol != null)
            {
                // We are loading exported functions from the currently running executable.
                pathResolver = new Host.Loader();
                loader       = new Host.Loader();
            }
            else
            {
                pathResolver = new DynamicLinkLibraryPathResolver();
                loader       = PlatformLoaderBase.SelectPlatformLoader();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // This custom path resolver attempts to do a DllImport to get the path that .NET decides.
                    // It may load a special dll from a NuGet package.
                    pathResolver = new WindowsDllImportLibraryPathResolver(pathResolver);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    pathResolver = new MacDllImportLibraryPathResolver(pathResolver);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    pathResolver = new LinuxDllImportLibraryPathResolver(pathResolver);
                }

                var resolveResult = pathResolver.Resolve("QmlNet");

                if (resolveResult.IsSuccess)
                {
                    libDirectory = Path.GetDirectoryName(resolveResult.Path);
                    if (!string.IsNullOrEmpty(libDirectory))
                    {
                        // If this library has a plugins/qml directory below it, set it.
                        var potentialPlugisDirectory = Path.Combine(libDirectory, "plugins");
                        if (Directory.Exists(potentialPlugisDirectory))
                        {
                            pluginsDirectory = potentialPlugisDirectory;
                        }

                        var potentialQmlDirectory = Path.Combine(libDirectory, "qml");
                        if (Directory.Exists(potentialQmlDirectory))
                        {
                            qmlDirectory = potentialQmlDirectory;
                        }
                    }
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (!string.IsNullOrEmpty(libDirectory) && Directory.Exists(libDirectory))
                    {
                        // Even though we opened up the native dll correctly, we need to add
                        // the folder to the path. The reason is because QML plugins aren't
                        // in the same directory and have trouble finding dependencies
                        // that are within our lib folder.
                        Environment.SetEnvironmentVariable(
                            "PATH",
                            Environment.GetEnvironmentVariable("PATH") + $";{libDirectory}");
                    }
                }
            }

            var result = pathResolver.Resolve("QmlNet");

            if (!result.IsSuccess)
            {
                throw new Exception("Couldn't find the native Qml.Net library.");
            }

            var library = loader.LoadLibrary(result.Path);

            Callbacks             = LoadInteropType <CallbacksInterop>(library, loader);
            NetTypeInfo           = LoadInteropType <NetTypeInfoInterop>(library, loader);
            NetJsValue            = LoadInteropType <NetJsValueInterop>(library, loader);
            NetMethodInfo         = LoadInteropType <NetMethodInfoInterop>(library, loader);
            NetPropertyInfo       = LoadInteropType <NetPropertyInfoInterop>(library, loader);
            NetTypeManager        = LoadInteropType <NetTypeManagerInterop>(library, loader);
            QGuiApplication       = LoadInteropType <QGuiApplicationInterop>(library, loader);
            QQmlApplicationEngine = LoadInteropType <QQmlApplicationEngineInterop>(library, loader);
            NetVariant            = LoadInteropType <NetVariantInterop>(library, loader);
            NetReference          = LoadInteropType <NetReferenceInterop>(library, loader);
            NetVariantList        = LoadInteropType <NetVariantListInterop>(library, loader);
            NetTestHelper         = LoadInteropType <NetTestHelperInterop>(library, loader);
            NetSignalInfo         = LoadInteropType <NetSignalInfoInterop>(library, loader);
            QResource             = LoadInteropType <QResourceInterop>(library, loader);
            NetDelegate           = LoadInteropType <NetDelegateInterop>(library, loader);
            QQuickStyle           = LoadInteropType <QQuickStyleInterop>(library, loader);
            QtInterop             = LoadInteropType <QtInterop>(library, loader);
            Utilities             = LoadInteropType <UtilitiesInterop>(library, loader);
            QtWebEngine           = LoadInteropType <QtWebEngineInterop>(library, loader);

            if (!string.IsNullOrEmpty(pluginsDirectory))
            {
                Qt.PutEnv("QT_PLUGIN_PATH", pluginsDirectory);
            }
            if (!string.IsNullOrEmpty(qmlDirectory))
            {
                Qt.PutEnv("QML2_IMPORT_PATH", qmlDirectory);
            }

            var cb = DefaultCallbacks.Callbacks();

            Callbacks.RegisterCallbacks(ref cb);
        }