Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Noob question about example code

Noob question about example code

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 807 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • bart.hollisB Offline
    bart.hollisB Offline
    bart.hollis
    wrote on last edited by
    #1

    In many of the examples provided by QT, that use access to a database, there is a run time test to see if the drivers have been loaded. My question: If I #include QtSql in my code, do I really need this test? If I make a call to sql without the include, I'll get a compile error. How can a program's source have an include and not have the drivers accessible? Why is this sample code included in the examples?

    K 1 Reply Last reply
    0
    • bart.hollisB bart.hollis

      In many of the examples provided by QT, that use access to a database, there is a run time test to see if the drivers have been loaded. My question: If I #include QtSql in my code, do I really need this test? If I make a call to sql without the include, I'll get a compile error. How can a program's source have an include and not have the drivers accessible? Why is this sample code included in the examples?

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @bart.hollis

      Yes. You test that the actual driver could be loaded. If you deploy somewhere your application and you forgot to deploy the appropriate driver or something happened to it, you will love the test!

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      4
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        To add to @koahnig, each driver is a plugin so when you open a database connection the appropriate plugin gets loaded unless theres a problem (usually missing dependencies). That's what you are seeing.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @bart-hollis think of the drivers as two part things: one is the definition (header file you use with #include) and then the implementation (driver), the actual code accessing the database.
          So not using #include gives you a compile-time error, since the compiler cannot see the "description" of operations/methods provided by a particular driver.
          Not having the driver available when you actually run your database-driven application gives you a runtime error, since something is missing at "run time". So the runtime check allows you to create a robust application that refuses to go on if some required component (in this case the driver!) is not available at that specific time.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          4
          • bart.hollisB Offline
            bart.hollisB Offline
            bart.hollis
            wrote on last edited by
            #5

            What a wonderful resource this forum is! Thank you all for your rapid and thorough responses. I only hope that some day I'll know enough to be able to return to the community at least a part of what I have received!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved