Skip to content

Commit aad3c03

Browse files
committed
Fixed the type map for QString to properly handle null.
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
1 parent 10a3dd6 commit aad3c03

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

QtSharp.CLI/Program.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,21 @@ public static int Main(string[] args)
9595
dependencies[libFile] = Enumerable.Empty<string>();
9696
}
9797
}
98-
var modules = new List<string> { "Qt5Core", "Qt5Gui", "Qt5Widgets", "Qt5Xml", "Qt5Designer", "Qt5Network", "Qt5Qml",
99-
"Qt5Nfc", "Qt5OpenGL", "Qt5ScriptTools", "Qt5Sensors", "Qt5SerialPort"};
98+
var modules = new List<string>
99+
{
100+
"Qt5Core",
101+
"Qt5Gui",
102+
"Qt5Widgets",
103+
"Qt5Xml",
104+
"Qt5Designer",
105+
"Qt5Network",
106+
"Qt5Qml",
107+
"Qt5Nfc",
108+
"Qt5OpenGL",
109+
"Qt5ScriptTools",
110+
"Qt5Sensors",
111+
"Qt5SerialPort"
112+
};
100113
if (debug)
101114
{
102115
for (var i = 0; i < modules.Count; i++)

QtSharp/QString.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public override string CSharpSignature(CSharpTypePrinterContext ctx)
2020

2121
public override void CSharpMarshalToNative(MarshalContext ctx)
2222
{
23-
ctx.SupportBefore.WriteLine("var __stringPtr{0} = (ushort*) Marshal.StringToHGlobalUni({1}).ToPointer();",
23+
ctx.SupportBefore.WriteLine("var __stringPtr{0} = ReferenceEquals({1}, null) ? null : (ushort*) Marshal.StringToHGlobalUni({1}).ToPointer();",
2424
ctx.ParameterIndex, ctx.Parameter.Name);
25-
ctx.SupportBefore.WriteLine("var __qstring{0} = QtCore.QString.FromUtf16(ref *__stringPtr{0}, {1}.Length);",
25+
ctx.SupportBefore.WriteLine("var __qstring{0} = __stringPtr{0} == null ? null : QtCore.QString.FromUtf16(ref *__stringPtr{0}, {1}.Length);",
2626
ctx.ParameterIndex, ctx.Parameter.Name);
2727
var type = ctx.Parameter.Type.Desugar();
2828
if (type.IsAddress())

0 commit comments

Comments
 (0)