libqmlbind icon indicating copy to clipboard operation
libqmlbind copied to clipboard

Documentation & Examples

Open rainbyte opened this issue 10 years ago • 9 comments

Hi.

I'm in process of writting vala bindings (WIP), and it would be really helpful to have some examples of the usage/workflow of this library.

Up to now I was trying to learn how to use it by reading the ruby-qml code, but some ruby specific concepts there are not easy to translate.

I've seen similar code from other projects too (like hsqml and qmlrs). It would be great to share efforts into a single C binding.

Thanks!


Known tasks:

rainbyte avatar Jun 19 '15 07:06 rainbyte

Examples like this could be useful:

/*
  Load a single QML file and start the application window.
  To compile:
      gcc -L /usr/lib -l :libqmlbind.so -o main main.c
*/

#include <qmlbind.h>

int main(int argc, char *argv[]) {

    qmlbind_application app = qmlbind_application_new(argc, argv);
    qmlbind_engine engine = qmlbind_engine_new();

    qmlbind_component component = qmlbind_component_new(engine);
    qmlbind_component_load_path(component, "main.qml");

    qmlbind_value object = qmlbind_component_create(component);

    int exit_code = qmlbind_application_exec(app);

    qmlbind_value_release(object);
    qmlbind_component_release(component);
    qmlbind_engine_release(engine);
    qmlbind_application_release(app);

    return exit_code;
}

rainbyte avatar Jun 19 '15 07:06 rainbyte

Just extended my example window code with proper exit code returning from your example as well as argc / argv forwarding. Totally forgot that code you posted here! :laughing:

florianjacob avatar Apr 03 '16 19:04 florianjacob

Hey, thanks for your work in this issue!

I think my idea, at that time, was to port at least ruby-qml examples.

Maybe it is easier now with the updated docs :)

rainbyte avatar Apr 03 '16 21:04 rainbyte

I think it's a great idea to collect & port the examples from already-known binding projects. :+1:

Not only because we then have examples helping to understand libqmlbind, but also because the code & concepts can be compared then.

Also, if we have high-quality examples in libqmlbind directly, new bindings can port the examples from C to the new binding language, instead of needing to think on their own.

Let's see how you'll get along with the new documentation, it's a nice test for it if another one writes the examples. :smile_cat:

florianjacob avatar Apr 04 '16 07:04 florianjacob

Collecting the examples directory of more binding projects, for reference:

I think screenshots like in ruby-qml are also a nice addition to see what you'll get as soon as you'll get it to run. The screenshots could also be reused in the actual language binding projects. :wink:

florianjacob avatar Apr 04 '16 08:04 florianjacob

I've made some progress with FizzBuzz example, but I got stuck making method callback work.

The code is here (it needs lots of cleanup).

Thanks in advance!

rainbyte avatar Apr 08 '16 03:04 rainbyte

Signal inputChanged is working as expected.

The original qml file was not modified.

Methods:

  • quit is called, but I don't know how to call qt app.quit().
  • onInputChanged, which fires on_changed, is not called.

rainbyte avatar Apr 08 '16 03:04 rainbyte

@rainbyte Thanks for implementing examples! Can you create a pull request for the fizzbuzz example? Then we can comment on it.

seanchas116 avatar Apr 08 '16 03:04 seanchas116

@seanchas116 , I've made a pull request here

rainbyte avatar Apr 08 '16 04:04 rainbyte