Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] QOCIDriver handle from QVariant to void *



  • 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



  • 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>();
    @



  • 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 *>();@



  • 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


Log in to reply