dotherside/D/DQml/main.d

68 lines
1.3 KiB
D
Raw Normal View History

2014-07-19 18:26:08 +02:00
import std.stdio;
import std.string;
import std.traits;
import std.conv;
import std.functional;
import core.memory;
2014-07-19 18:26:08 +02:00
import dotherside;
class MyObject : QObject
2014-07-19 18:26:08 +02:00
{
this()
{
2014-08-30 18:46:34 +02:00
foo = registerSlot("foo", &_foo);
2014-07-19 18:26:08 +02:00
bar = registerSlot("bar", &_bar);
nameChanged = registerSignal!(string)("nameChanged");
2014-08-30 18:46:34 +02:00
tor = registerSlot("tor", &_tor);
2014-07-19 18:26:08 +02:00
}
public QSlot!(void delegate(int)) foo;
private void _foo(int fooValue)
2014-07-19 18:26:08 +02:00
{
writeln("D: Called foo slot with argument ", fooValue , "!!");
2014-07-19 18:26:08 +02:00
}
public QSlot!(int delegate(int)) bar;
private int _bar(int barValue)
2014-07-19 18:26:08 +02:00
{
writeln("D: Called bar slot with argument " , barValue, "!!");
2014-07-19 18:26:08 +02:00
return 666;
}
2014-08-30 18:46:34 +02:00
public QSlot!(string delegate(string)) tor;
private string _tor (string torValue)
2014-08-30 18:46:34 +02:00
{
writeln("D: Called tor slot with argument ", torValue, "!!");
return "2343";
}
public QSignal!(string) nameChanged;
2014-07-19 18:26:08 +02:00
}
void main()
{
try
{
auto app = new QGuiApplication;
scope(exit) destroy(app);
2014-08-30 18:46:34 +02:00
auto view = new QQuickView;
scope(exit) destroy(view);
2014-07-19 18:26:08 +02:00
auto myObject = new MyObject();
scope(exit) destroy(myObject);
2014-07-19 18:26:08 +02:00
auto context = view.rootContext();
context.setContextProperty("myObject", new QVariant(myObject));
view.setSource("Test.qml");
view.show();
2014-08-30 18:46:34 +02:00
myObject.nameChanged("prova");
2014-07-19 18:26:08 +02:00
app.exec();
}
catch
{}
}