GUI library for D

Adam D. Ruppe destructionator at gmail.com
Mon Apr 4 20:55:14 PDT 2011


Nick Sabalausky wrote:
> Should "pragma(lib, nameoflib);" work, or was that just a special
> thing in bu(il)d?

Yes, that should work. I use it in my curl and mysql modules which
I use with straight DMD (as well as my own little build tool, which
simply downloads referenced modules from my http server and builds
the dmd command line automatically. http://arsdnet.net/dcode/build.d )

> That should help. It does seem that QtD could *really* use some
> D-ification, though.

Absolutely. That's one reason why I actually prefer my later
approach of doing my own approach - one version of my D windowing
system plan.

Here's some snippets from the program written in it (it's closed
source commercial for a client company, so can't post the whole
thing):

       // it uses runtime Qt Designer loading to avoid the long
       // process of porting all that code. Acts as a "release
       // valve" if you will from the limitations of my system.
       // the .ui file is created straight from the C++ tool
        auto window = new QtUicWidget(import("stb.ui"));
        window.show();

        // thanks to some opDispatch magic though, it feels almost
        // like a regular class, though you need to do dynamic casts
        auto accountBox = cast(TreeWidget) window.accountBox;

        // Arrays of delegates let you handle events. A few
        // different signatures for handlers are allowed.
        // (it's actually a struct emulating a delegate array)
        window.accountProvider.textChanged ~= (Variant[] args) {
             // snip
        }

         // unrelated by cool: my DataObject system works with sqlite too, along
with mysql and postgres (to a limited extent)!
        auto db = openDBAndCreateIfNotPresent("stb.db", import("stb.sql") [...]


            // qtConnect is another one of my escape valves
           // if I don't offer a D wrapper, you can still access
           // Qt events via strings, with extensions for D
           // delegates!
                qtConnect(dialog.getKeyButton, "clicked()", {
                        dwsapp.openBrowser("http://mysite.com");
                });


The thing above is implemented via a bunch of helper objects on
the C++ side, put into a QSignalMapper. It actually leaks a
little memory since there's no facility to delete the C++ object,
but it was too convenient to have.

You can also connect C++ signals to C++ slots directly, using the
same string syntax, just like in QtD. I found the delegates so
much more useful though that I always used them in this app.

        // a technique I first started using in Javascript that
        // I also use in D now too - a function creates a delegate
        // so it can be called in a loop, closing over the loop var
        void delegate() makeTextChanged(Item i, string id) {

        // Menu items are Actions, like in C++, but the delegate
        // is provided right there.
        auto newAccountAction = new Action("&New Account", {
                newAccount("", "New Account");
        });

        // property syntax for get/set
        newAccountAction.icon = new Image(cast(bytes) import("add.png"));

        // another escape valve - access C++ objects dynamically
        // It actually builds wrapper objects at runtime from the
        // .ui file so you can use the D extensions on it too
        window.actions["action_About"].triggered ~= {

        // Qt supports CSS, so I did that here too, extending it
        // for HSL colors (it was mentioned on the newsgroup and
        // I liked it!)
        window.setStyleSheet(fixupStylesheetHsl(`

        // the C++ event loop is put into a separate gui thread
        // all wrapped up in this call:
        int retv = dws.eventLoop();



Like I've said before about the dws, I really want to make it work
with a shitty javascript front end too - and made some progress
in an earlier version - but the Qt got more attention here since
I needed it for a work project and was under the clock. Hence,
the escape valves and relatively limited native functions.


But, like with all my D libraries, I do keep the copyright on
all of it, even when it's done directly for work, so I could
clean this up for release.

It uses some C++0x features in the DLL code, so it might be a
pain to compile, but I could distribute binaries; it's about 1 MB,
negligble next to Qt itself.

It works on both Windows and Linux.


More information about the Digitalmars-d mailing list