mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-21 06:45:32 -06:00
Added support for getting the Qt version.
This commit is contained in:
parent
b1bb31a3a4
commit
9fffc86bcd
3 changed files with 48 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include <QmlNet/qml/QCommon.h>
|
||||
#include <QtGlobal>
|
||||
#include <QString>
|
||||
#include <QmlNetUtilities.h>
|
||||
|
||||
|
|
@ -6,7 +7,11 @@ extern "C" {
|
|||
|
||||
Q_DECL_EXPORT bool qt_putenv(LPCSTR name, LPCSTR value)
|
||||
{
|
||||
return qputenv(name, value);
|
||||
if(value == nullptr) {
|
||||
return qunsetenv(name);
|
||||
} else {
|
||||
return qputenv(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
Q_DECL_EXPORT QmlNetStringContainer* qt_getenv(LPCSTR name)
|
||||
|
|
@ -19,4 +24,9 @@ Q_DECL_EXPORT QmlNetStringContainer* qt_getenv(LPCSTR name)
|
|||
return createString(string);
|
||||
}
|
||||
|
||||
Q_DECL_EXPORT QmlNetStringContainer* qt_version() {
|
||||
QString version(qVersion());
|
||||
return createString(version);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
29
src/net/Qml.Net.Tests/Qml/CommonTests.cs
Normal file
29
src/net/Qml.Net.Tests/Qml/CommonTests.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace Qml.Net.Tests.Qml
|
||||
{
|
||||
public class CommonTests
|
||||
{
|
||||
[Fact]
|
||||
public void Can_put_and_get_env()
|
||||
{
|
||||
var envName = Guid.NewGuid().ToString().Replace("-", "");
|
||||
Qt.GetEnv(envName).Should().BeNull();
|
||||
Qt.PutEnv(envName, "");
|
||||
Qt.GetEnv(envName).Should().BeEmpty();
|
||||
Qt.PutEnv(envName, "TEST");
|
||||
Qt.GetEnv(envName).Should().Be("TEST");
|
||||
Qt.PutEnv(envName, null);
|
||||
Qt.GetEnv(envName).Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Can_get_qt_version()
|
||||
{
|
||||
var version = Qt.GetQtVersion();
|
||||
version.Major.Should().Be(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,12 @@ namespace Qml.Net
|
|||
public static string GetEnv(string name)
|
||||
{
|
||||
return Utilities.ContainerToString(Interop.QtInterop.GetEnv(name));
|
||||
}
|
||||
}
|
||||
|
||||
public static Version GetQtVersion()
|
||||
{
|
||||
return Version.Parse(Utilities.ContainerToString(Interop.QtInterop.QtVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
internal interface IQtInterop
|
||||
|
|
@ -26,5 +31,7 @@ namespace Qml.Net
|
|||
bool PutEnv([MarshalAs(UnmanagedType.LPStr), CallerFree]string name, [MarshalAs(UnmanagedType.LPStr), CallerFree]string value);
|
||||
[NativeSymbol(Entrypoint = "qt_getenv")]
|
||||
IntPtr GetEnv(string name);
|
||||
[NativeSymbol(Entrypoint = "qt_version")]
|
||||
IntPtr QtVersion();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue