Cutelyst a Qt web framework

Do you recall that “Qt everywhere” branding?

Well that’s one of the things I really like in Qt, being able to deploy everywhere with minimal to zero changes in source code. But sometimes your application needs a web interface some sort of web backend or web admin, and when that happens it breaks that slogan (AFAIK)…

I got in contact with web languages (not HTML) only when at university, ColdFusion and PHP where the first ones, and while PHP was sort of cool because it has a syntax close to C, I never really like it. I’m not a web designer nor know how to do pretty websites, but in today’s world building web apps is inevitable.

So years ago I learned about RubyOnRails, and people where talking all the good stuff about it, it’s was the framework of the hype, although I knew Ruby wasn’t the fastest scripted language my need didn’t demand that, so I got a book, read it cover to cover and happily started my web app, a week latter I got a complex problem with an apparently impossible solution. It seemed that RoR makes easy things stupidly easy and complex things impossible…

The I met Catalyst a Perl framework, got exited again, but I knew nothing about Perl so I read more 3 books and was started to love the language, I still do, but last weekend when trying to resurrect and old Catalyst application I got an error which I had no idea how to fix, on IRC I was told the problem could be that I mixed CPAN packages with distro packages, not very convinced I realized the bigger problem I was actually facing, I’m not fluent in Perl, well no matter how many books you read about a language you only get fluency in it after speaking it almost everyday, this applies to computing languages too of course.

So if 99% of the time (or less now with QML) I’m programming C++ it means that I know a lot more about how to debug it than with Perl, so Cutelyst! Writting web apps in Qt/C++ will be much more efficient to me and hopefully to you too.

I share lots of the Catalyst API and design ideas, tho the implementation is of course completely different. Also for the sake of HTML templating I plan to create a Grantlee View plugin.

You can take a look at the proof of concept:

https://gitorious.org/cutelyst

Have fun.

Cutelyst a Qt web framework

26 thoughts on “Cutelyst a Qt web framework

    1. dantti says:

      Hmmm ok, you can notice the AFAIK on the text since I didn’t know about them.
      Of course I’ll take a look, but considering that Django (not qdjango) is the framework which made me hate Python, on a company that I used to work some smart guy decided to use it while it was very new project, that mess changed API everyday and the only reliable documentation was the source code. Also the design is quite different from Perl Catalyst, Tufao OTOH is interesting, but I think what we can share is mostly some interesting bits like HTTP parsing, tho Cutelyst will also offer a FastCGI engine.

      1. dantti says:

        Well it was the product that introduced me to the language, which I dislike even without the project 😛

      1. You don’t need to write HTML with functions, just use WText to write whatever you want.

        I do like the idea of Wt taking care of browser differences, bugs and tricks. These days there is a lot more than one can think to writing a webapp.

  1. Hi,

    If writing web applications in C++ and using a Qt-like approach interests you, you may want to have a look at WebToolkit (webtoolkit.eu). It is a C++ web framework licensed under the GPL (and a commercial license if you don’t want GPL) that is very powerful. It takes some time to get used to it and to how it works (for instance, your whole application is made of widgets, that you modify and combine exactly as you do with Qt, and templates are only one of the multiple available widgets, see WTemplateWidget), but many complex things are possible.

    With Wt, you don’t have to write any Javascript to support complex AJAX interactions. When an event occurs on the client, your server application is notified and you can modify all the widgets you want (you can change the text of a button, of a field, of a template, etc). When you are done, Wt sends to the client the difference between the old application state and the new one, and the client page is updated. When the client doesn’t support Javascript, Wt still works : instead of sending the differences to the client (that updates its DOM tree using them), Wt sends a complete new version of the web page, and no Javascript is needed.

    Wt comes with a somewhat nice ORM, the Wt ORM. It supports SQLite, MySQL and PostreSQL I think. I don’t have much experience with this ORM as I needed to mix Qt code and Wt code, and the Wt ORM doesn’t integrate well with Qt. I developed QtORM (https://github.com/steckdenis/qtorm), that you may find interesting. I use this ORM in production, but it may lack features and is currently not documented.

    1. dantti says:

      Yes, I know about it, the first problem is writting html with functions, I just dislike that, it also doesn’t seem to be as flexibe as Perl Catalyst is. Second is indeed the license, I want something that is LGPL that I can just link against.
      If you look at Perl Catalyst you will understand why the design ideas are very different.
      And BTW there is a ORM that supports Qt I just don’t recall the naming but might help you.

  2. rqx says:

    This is great, exactly what I’m looking for right now for a hobby project and what we’d have needed 1 year ago at my company. But I think it might be useful for new devices we start building (we just switched from pure C++ to Qt/C++ as standard).
    I’ll try it 🙂

    1. dantti says:

      Well before I even start to read a book about it I heard people saying Ruby was slow, but since the app didn’t need to be blazing fast I ignored this and started reading the book. The problem I had might not be valid today but iirc I needed a simple multiselection list which just turned out to be a mess to handle, I really enjoyed the language but it was slow indeed and at that time the lack of managing more than one db connection was also something that would be a problem to me.

      1. Paul Dann says:

        Ruby isn’t as slow as all that nowadays, although it is naturally slower than some other languages; that’s the price of its flexibility. I’ve found that caching usually makes a huge difference in web apps, and I like the speed with which it’s possible to throw something together in Ruby. Conversely, I also enjoy the slower-and-more-careful approach of writing C++ for projects that require more care and efficiency. Rails is geared toward horizontal scaling, and does it very well.

        You might have been after this: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-select_tag

        Not looking to say you should have used Rails or whatever; mostly to expand my own horizons: I’ve never needed multiple database connections; could you share that usecase?

      2. dantti says:

        Well it’s been more than 5 years since I touched it so it might have become faster (although I haven’t seem news about this).

        Also I don’t think it’s slow at all to write C++ apps, it all depends on how familiar you are with the language and the toolkit, I for example love Perl Catalyst design but I’m not efficient in writing/debugging Perl apps.

        And I disagree about a framework being designed for scalability, the way that you design your app tells how well can you scale in multiple servers which isn’t related to speed or framework.

        There are lots of interesting stuff to do with multiple databases, for instance you could deploy several instances of your application to multiple clients each with it’s own db, but manage the user accounts into a single db (maybe LDAP would be better). There are also some apps where I work that need to fetch data for several different applications where each of them has it’s own db..

      3. Paul Dann says:

        Yeah fair enough: Rails isn’t aimed at that kind of design; it is so-called “opinionated” software. From the Ruby world, though, Sinatra comes in a little lower-level, and would probably suit that kind of usecase more.

        When I say it’s slower to write C++ apps, I’m thinking mainly about the thinking required by (for instance) strong typing, worrying about overflows, resource handling, etc… Don’t get me wrong, though: I love Qt/C++, and those things also have great benefits. It’ll be really interesting to see C++ in this kind of web framework league.

    1. dantti says:

      Sure, I’m planning a 0.1 release probably next week, but first I need to make most basic stuff start working…

    1. dantti says:

      The idea is cool but this is a bit heavy thing, also I’m interested in having more control for html stuff

    1. dantti says:

      It’s a nice framework, which I didn’t know before writing this, but I like the Catalyst simple and plugable approach, I also like more how the dispatch system works and action’s attributes.
      For example instead of having my own http server I use uWSGI to avoid such work, if some other better option arrives it just need to subclass the Engine class.
      And from the data on their website Cutelyst seems to be faster, tho I didn’t do a testing side-by-side my machine is the same from their testing…

  3. João says:

    Daniel, could you please tell me the differences between cutelyst and emscripten?
    (if it helps you i know portuguese even better than english)

    1. dantti says:

      I don’t know much of emscripten, but from Wikipedia it’s something not much comparable to Cutelyst. Cutelyst is backend code, receiveing HTTP requests, processing and sending replies in HTML, Json, whatever.. emscripten seemed to me a different way to write JavaScript code for the client browser to compile and execute. This is probably not much accurate, but as I said I never used and know little about emscripten.

      1. João says:

        Well, from what i understand about emscripten, i write C++ (in qt creator, for example) and then emscripten translates C++ into html+JS.

        but this way i’m not actually using C++, but JS.

        Is cutelyst any different?

        I ask this because what would indeed be nice would be the actual “build once, deploy everywhere” using the same code, not a “translated / alien” one.

  4. dantti says:

    Yes, Cutelyst is completely different, it doesn’t generate HTML, JS, JSON or anything else by itself.
    You write in C++, generate a binary library and it runs with uWSGI or cutelyst-wsgi on your webserver, you can compare it to DJango, with some PHP framework, Ruby on Rails, ASP. I believe you can still use emscripten with Cutelyst since it would simply serve the HTML+JS generated by it.

Leave a comment