Results 1 to 2 of 2

Thread: Connect Graphics Scene to SQL relational Model

  1. #1
    Join Date
    Mar 2016
    Posts
    16
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Connect Graphics Scene to SQL relational Model

    There is an example distributed with Qt called "diagramscene". In the application, the user creates a variety of graphics objects in the Graphics Scene. I am interested in saving this data in a relational database. One table with the list of objects and the second table with the connections between the objects. What would it take to connect the objects to a QSQLRelationalTableModel"? What classes do I need to allow retrieving the data, edit, and saving the data?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,239
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Connect Graphics Scene to SQL relational Model

    I would approach this from the opposite direction. Instead of having a graphics scene update a database, have the database update the graphics scene. The user interactions add entries to the database model, which then issues signals to cause updates to the scene as displayed on screen.

    I've done something similar in my current application - everything that is displayed onscreen is implemented as a class derived from QAbstractItemModel, and there are "glue" classes that listen for model signals and invoke updates to the graphics.

    If you derive a class from QGraphicsScene and add slots to connect it to the SQL model's signals (modelReset(), dataChanged(), etc.) as well as storing a pointer to the model, then you can use the model's signals to update the scene. The QGraphicsView instances attached to the scene will automatically update with changes to the scene.

    Your database will also have to keep track of the parent-child relationships between graphics items, unless your design has all objects as top level members of a scene.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 6
    Last Post: 22nd November 2011, 03:53
  2. Q Table View + Relational Model VERY SLOW
    By arimaniac in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2010, 16:43
  3. graphics scene
    By dognzhe in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2009, 08:55
  4. Relational table model Calulation
    By aekilic in forum Qt Programming
    Replies: 8
    Last Post: 7th February 2007, 23:40
  5. Relational Table Model Problem
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2007, 14:57

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.