Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] QOCIDriver handle from QVariant to void *

    General and Desktop
    2
    4
    2262
    Loading More Posts
    • 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.
    • G
      Galbarad last edited by

      Hi all
      I have problem with getting OCI handle
      I try following code
      @QSqlDriver *driver = connect.driver(); // get pointer to driver
      QVariant h = driver->handle(); // get QVariant handle
      void *vh = h.value<void *>(); // in this point I\m receive 0 @

      this is part of QOCIDriver that return handle
      @
      QVariant QOCIDriver::handle() const
      {
      // d->env -pointer to OCIEnv ( type OCIEnv * )
      return QVariant::fromValue(d->env);
      }@

      How I can tear off my OCIEnv * from QVariant ?

      thank you

      1 Reply Last reply Reply Quote 0
      • C
        ChrisW67 last edited by

        It returns 0 because the QVariant is of custom type OCIStmt* (declared in qsql_oci.cpp and also mentioned in the comment). Try:
        @
        OCIStmt handle = h.value<OCIStmt>();
        @

        1 Reply Last reply Reply Quote 0
        • G
          Galbarad last edited by

          Hi thank you for you reply, but OCIStmt return as handle in another class
          @QVariant QOCIResult::handle() const
          {
          return QVariant::fromValue(d->sql);
          }@

          QOCIDriver return OCIEnv *env;

          but even I try
          @OCIEnv *vhh = h.value<OCIEnv *>();@

          I receive compilation errors
          use of undefined type 'OCIEnv'
          Type argument of Q_DECLARE_METATYPE(T*) must be fully defined
          E:\Qt\Qt5.0.0\5.0.0\msvc2010\include\QtCore\qmetatype.h 464

          declaration type OCIEnv in oci.h
          @typedef struct OCIEnv OCIEnv; /* OCI environment handle */@

          as I read somewhere in Internet QVariant store not simple and not QObject values in void * so I suppose that I can take my value through
          @void *vh = h.value<void *>();@

          1 Reply Last reply Reply Quote 0
          • G
            Galbarad last edited by

            problem solved
            just use
            @QVariant QOCIDriver::handle() const
            {
            // d->env -pointer to OCIEnv ( type OCIEnv * )
            return QVariant::fromValue((void *)d->env);
            }@

            instead of

            @QVariant QOCIDriver::handle() const
            {
            // d->env -pointer to OCIEnv ( type OCIEnv * )
            return QVariant::fromValue(d->env);
            }@

            How I can add my own method into QOCIDriver??? for example getServerHandle?

            thanks

            1 Reply Last reply Reply Quote 0
            • First post
              Last post