Browse Source

qt: add handwritten QString because generated version had problems

pull/1/head
Alexander Corrado 14 years ago
parent
commit
0d5dd66117
  1. 19
      src/qt/Makefile.am
  2. 66
      src/qt/QString.cs
  3. 22
      src/qt/hello.cs

19
src/qt/Makefile.am

@ -1,28 +1,29 @@ @@ -1,28 +1,29 @@
top_srcdir = ../..
INTEROP_DLL = \
$(top_srcdir)/src/Mono.VisualC.Interop/bin/Debug/Mono.VisualC.Interop.dll
$(top_srcdir)/bin/Debug/Mono.Cxxi.dll
all: hello.exe
qt-gui.xml: qt-gui.h
gccxml -fxml=$@ --gccxml-cxxflags "`pkg-config --cflags QtCore QtGui`" qt-gui.h
$(GCCXML) -fxml=$@ --gccxml-cxxflags "`pkg-config --cflags QtCore QtGui`" qt-gui.h
generated: qt-gui.xml
$(RM) -r generated
mono --debug $(top_srcdir)/src/generator/bin/Debug/generator.exe -o=generated -ns=Qt.Gui -lib=QtGui --filters=qt-gui-filters.txt qt-gui.xml
$(MONO) --debug $(top_srcdir)/bin/Debug/generator.exe -o=generated -ns=Qt.Gui -lib=QtGui --filters=qt-gui-filters.txt qt-gui.xml
libQtGui-inline.so: qt-gui.cpp
g++ `pkg-config --cflags QtCore QtGui` --shared -fPIC -o $@ -fkeep-inline-functions qt-gui.cpp `pkg-config --libs QtCore QtGui`
#libQtGui-inline.so: qt-gui.cpp
# $(CXX) `pkg-config --cflags QtCore QtGui` --shared -fPIC -o $@ -fkeep-inline-functions qt-gui.cpp `pkg-config --libs QtCore QtGui`
Qt.Gui-binding.dll: generated
$(GMCS) -out:$@ -target:library -unsafe -r:$(INTEROP_DLL) generated/*.cs
Qt.Gui-binding.dll: generated QString.cs
rm generated/QString.cs
$(GMCS) -out:$@ -target:library -unsafe -r:$(INTEROP_DLL) generated/*.cs QString.cs
hello.exe: Qt.Gui-binding.dll hello.cs libQtGui-inline.so
hello.exe: Qt.Gui-binding.dll hello.cs #libQtGui-inline.so
$(GMCS) -out:$@ -target:exe -r:$(INTEROP_DLL) -r:Qt.Gui-binding.dll hello.cs
clean:
$(RM) -rf generated hello.exe qt-gui.xml Qt.Gui-binding.dll libQtGui-inline.so
run: hello.exe
MONO_PATH=$(top_srcdir)/src/Mono.VisualC.Interop/bin/Debug mono hello.exe
MONO_PATH=$(top_srcdir)/bin/Debug $(MONO) hello.exe

66
src/qt/QString.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
using System;
using System.Text;
using System.Runtime.InteropServices;
using Mono.Cxxi;
namespace Qt.Gui {
//TODO: Will this leak?
[StructLayout (LayoutKind.Sequential)]
public unsafe struct QString {
#region Sync with qstring.h
public interface IQString : ICppClass {
[Constructor] void QString(ref QString @this, [MangleAs ("const QChar*")] IntPtr unicode, int size);
}
[StructLayout (LayoutKind.Sequential)]
public struct Data {
public int @ref;
public int alloc, size;
public IntPtr data;
public ushort clean;
public ushort simpletext;
public ushort righttoleft;
public ushort asciiCache;
public ushort capacity;
public ushort reserved;
public IntPtr array;
}
public Data* d;
#endregion
private static IQString impl = Libs.QtGui.GetClass<IQString> ("QString");
public QString (string str) : this ()
{
var strPtr = Marshal.StringToHGlobalUni (str);
impl.QString (ref this, strPtr, str.Length);
Marshal.FreeHGlobal (strPtr);
// TODO: I deref this on construction to let Qt free it when it's done with it.
// My assumption is that this struct will only be used to interop with Qt and
// no managed class is going to hold on to it.
this.DeRef ();
}
public static implicit operator QString (string str)
{
return new QString (str);
}
public QString AddRef ()
{
d->@ref++;
return this;
}
public QString DeRef ()
{
d->@ref--;
return this;
}
}
}

22
src/qt/hello.cs

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
using System;
using Qt.Gui;
using Mono.VisualC.Interop;
using Mono.Cxxi;
namespace QtTest {
class MainClass {
@ -9,29 +9,11 @@ namespace QtTest { @@ -9,29 +9,11 @@ namespace QtTest {
{
int argc = args.Length;
using (QApplication app = new QApplication (ref argc, args, 0x040602)) {
QPushButton hello = new QPushButton (QString.FromUtf8 ("Hello", 5), null);
QPushButton hello = new QPushButton ("Hello", null);
hello.Resize (100, 30);
hello.Show ();
CppLibrary.SaveInteropAssembly ();
QApplication.Exec ();
}
/*
using (QPushButton hello = new QPushButton ("Hello world!"),
hello2 = new QPushButton ("Another button")) {
hello.Resize (100, 30);
hello2.Resize (200, 30);
//CppLibrary.SaveInteropAssembly ();
hello.Visible = true;
hello2.Visible = true;
app.Exec ();
}
}
*/
}
}
}

Loading…
Cancel
Save