Results 1 to 2 of 2

Thread: Imperative workflow in C++/Qml application

  1. #1
    Join Date
    Sep 2013
    Posts
    9
    Thanked 1 Time in 1 Post

    Default Imperative workflow in C++/Qml application

    Hi,

    I'm working on a desktop application written in C++ with UI code in Qml. It's a typical 3d (engineering) application (think something like autocad, 3dsmax,..., but smaller). There is one thing which often comes back and to which I didn't find a satisfying solution yet and that's handling "a workflow with questions to the user". To give an example: Let's say the user wants to start a new project when another one is open - if there are changes, ask whether to save them or not - if no, quit, start a new project and ask properties for this project to open, if yes, check if there is already a file/folder to save - if no, ask a file to save, if yes check the types of items in the project - Depending on the type of items, ask the user if they are needed to be saved in the project or not - if not, go to next type, if yes, check if this item type needs certain "save settings" (for instance compression factor of a picture, whether to save a 3d model binary or ascii,...), and so on and so on... .
    Every time, i try to invent a new approach to solve such problems, but I never found a good solution. The reason is there is a lot of (already working) imperative code (and my mindset is probably to imperative :-)). Is there some sort of design pattern to follow to keep this clean? Or how do you solve such problems?
    Thanks for the ideas,

    Jan

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,357
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Imperative workflow in C++/Qml application

    As you've said yourself there are quite a number of ways to do that.

    One approach that i find rather elegant myself is the request handler pattern used for example by the QML API of WebEngineView.

    The C++ side emits a signal that transports a request context, which is then used by the QML side to communicate the result back.

    See for example http://doc.qt.io/qt-5/qml-qtwebengin...quested-signal

    If you know or require that the QML side uses a modal dialog and thus a nested event loop, then you can retrieve the user's input right after the emit returns.

    Qt Code:
    1. RequestContext context;
    2.  
    3. emit requestDialog(&context);
    4.  
    5. // continue in "linear" workflow
    To copy to clipboard, switch view to plain text mode 

    If you want to handle the nested event loop on the C++ side, it will look more like this:
    Qt Code:
    1. RequestContext context;
    2.  
    3. connect(&context, &RequestContext::done, &loop, &QEventLoop::quit);
    4.  
    5. emit requestDialog(&context);
    6.  
    7. // check if dialog has not already been
    8. if (!context.isDone() {
    9. loop.exec();
    10. }
    11.  
    12. // continue in "linear" workflow
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Qt YAWL (or other workflow engine) Clients?
    By sdeerwester in forum Qt-based Software
    Replies: 0
    Last Post: 17th June 2014, 15:37
  2. Replies: 4
    Last Post: 19th November 2012, 14:35
  3. Replies: 1
    Last Post: 30th May 2011, 13:46
  4. QT on VS2008 workflow
    By killrazor in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 10:01
  5. Workflow Designer
    By arjoshi in forum Qt Programming
    Replies: 2
    Last Post: 1st December 2008, 04:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.