Skip to content

KDE/qyoto

Repository files navigation

README
------

Qyoto comprises of set of C# classes wrapping the Qt 4.3 library for
use with Mono/.NET, along with a runtime that interfaces with the
language independent Smoke library that was originally designed for
PerlQt and is currently also used for QtRuby.

The API is pretty much the same as the C++ one, the main differences
being the following:

 - Method names begin with a capital letter

 - Q_PROPERTYs are mapped onto .NET properties and, for example, the
property 'windowTitle' with the accessors 'setWindowTitle()'
and 'windowTitle()' becomes just a 'WindowTitle' property
in .NET/Mono.

 - The declaration of signals/slots is slightly different, although
the QMetaObject created at runtime for QObject subclasses is
identical to the equivalent C++ class:

To mark methods as slots, just add a Q_SLOT attribute to them.
For example:

[Q_SLOT]
void ButtonClicked() {
    // do something
}


Each QObject subclass with signals, has a signals interface with the
method signatures of all the signals for that class. To create custom
signals, you first have to create an interface which inherits from
the signals interface of the parent class. In this interface you
declare your signals, all marked with the Q_SIGNAL attribute. Then
you need to override the Property 'Emit' of the class for which you
want to emit the custom signals. The return value of 'Emit' is the
protected variable Q_EMIT (actually a transparent proxy), casted to
the type of the class's signals interface.

To emit a signal, use 'Emit.SignalName(<an optional arg list>)'

For example:

class Test : QWidget {
    // some code
    
    protected ITestSignals Emit { get { return (ITestSignals)
Q_EMIT; } }
    
    public void MyMethod() {
        // here we emit our custom signal
        Emit.TestSignal(5);
    }
    
    // some code
}

interface ITestSignals {
    [Q_SIGNAL]
    void TestSignal(int arg1);
}


Signals and slots are connected in the same way as for C++, except
that the signal and slot signatures are strings. For instance:

Connect(qApp, SIGNAL("aboutToQuit()"), this, SLOT("quit()"));

Qyoto also provides a set of tools for use with Qt Designer .ui files
and resources in .rcc files, uics and csrcc (ports of uic and rcc to
produce C# code). Invocation from the command line is the same as for
the C++ tools. To use your generated GUI code, first create an
instance of the Ui class, then call SetupUi() with the current widget
as parameter and your GUI will be set up, just like in C++.

For example:

class Test : QWidget {
    Ui.Form ui;
    
    public Test() {
        ui = new Ui.Form(),
        ui.SetupUi(this);
    }
}

To use resources, just compile the generated code into your
application and then call Q_INIT_RESOURCE() in Main().
Excerpt from the simpletreeview example:

public static int Main(string[] args) {
    Q_INIT_RESOURCE("simpletreemodel");
    new QApplication(args);
    QFile file = new QFile(":/default.txt");
    
    // more code...
}