Results 1 to 20 of 61

Thread: using an isntance of QSqlDatabase for connection defiinition

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: using an isntance of QSqlDatabase for connection defiinition

    Quote Originally Posted by jfinn88 View Post
    I can pass it with the sql statement correct ?
    Yes.

    Quote Originally Posted by jfinn88 View Post
    Will calling addEvent () in the while loop be fine or should it be called once after the while loop is done putting data in struct?
    In every loop iteration.
    You can basically keep your code, but instead of calling addEvent() on a different model you just call addEvent() of the current object.

    Quote Originally Posted by jfinn88 View Post
    I’m still little confused how the virtual functions get called... from my understanding is when the instance variable of my class is created (to pass the model to C++ by setting rootContext item) it makes a call to the constructor and when the constructor gets called the virtual functions get called (trying to clear any confuse I still have with models and virtual functions) ?
    When you create an object, the constructor for that class is called.

    Once the object is created, calls to virtual functions always end up in the most specific subclass.
    E.g. if you overwrite roleNames() a call to roleNames() will end up calling your implementation.

    Quote Originally Posted by jfinn88 View Post
    Also I want to call dbConnect and selectQuery() methods from QML (button click)
    For what purpose?
    I can see a use case of re-running the query on demand, but dbConnect?
    dbConnect() is really internal, no? It has to be called before database access happens, so the class itself should know when to call it.

    Quote Originally Posted by jfinn88 View Post
    in the header file I declare the function as Q_INVOKABLE now I know I could register the QML type to make the class accessible in QML and import it in the QML to call the function but I think I would have to make the class global object? is there a simpler way to do this ?
    That is unnecessary.
    Q_INVOKABLE methods and slots are already accessible as functions on an object set as a context property.
    Registration of a type is only necessary if instances of that type need to be created from QML or if it has enum definitions where the QML code should be able to use the names.

    Quote Originally Posted by jfinn88 View Post
    I have seen an example with Q_INVOKABLE and setting the context property, but I get confused on what engine object/class I need to use to set it.
    You don't have to change anything in your code.

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    jfinn88 (26th August 2016)

Similar Threads

  1. Replies: 16
    Last Post: 4th September 2013, 00:49
  2. How to set x509 on a QSqlDatabase Connection?
    By m3rlin in forum Qt Programming
    Replies: 24
    Last Post: 21st February 2012, 04:04
  3. Windows OCI QSqlDatabase connection
    By hollyberry in forum Newbie
    Replies: 10
    Last Post: 13th February 2012, 22:13
  4. QSqlDatabase Connection Close on Destruction
    By Sanuden in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2011, 15:32
  5. QSqlDatabase connection timeout?
    By joseprl89 in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2011, 01:43

Tags for this Thread

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.