Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

What is the difference between configuring QT with -no-exceptions and -DQT_NO_EXCEPTIONS?



  • What is the difference between -no-exceptions and -DQT_NO_EXCEPTIONS? And what is right way to get rid of “try { } catch (…) {}” in qtbase\src\corelib\thread\qthread_unix.cpp?

    void *QThreadPrivate::start(void *arg)
    {
    #if !defined(Q_OS_ANDROID)
        pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
    #endif
        pthread_cleanup_push(QThreadPrivate::finish, arg);
    
    #ifndef QT_NO_EXCEPTIONS
        try
    #endif
        {
            QThread *thr = reinterpret_cast<QThread *>(arg);
            QThreadData *data = QThreadData::get2(thr);
    
            {
                QMutexLocker locker(&thr->d_func()->mutex);
    
                // do we need to reset the thread priority?
                if (int(thr->d_func()->priority) & ThreadPriorityResetFlag) {
                    thr->d_func()->setPriority(QThread::Priority(thr->d_func()->priority & ~ThreadPriorityResetFlag));
                }
    
                data->threadId.store(to_HANDLE(pthread_self()));
                set_thread_data(data);
    
                data->ref();
                data->quitNow = thr->d_func()->exited;
            }
    
            if (data->eventDispatcher.load()) // custom event dispatcher set?
                data->eventDispatcher.load()->startingUp();
            else
                createEventDispatcher(data);
    
    #if (defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_QNX))
            {
                // sets the name of the current thread.
                QString objectName = thr->objectName();
    
                pthread_t thread_id = from_HANDLE<pthread_t>(data->threadId.load());
                if (Q_LIKELY(objectName.isEmpty()))
                    setCurrentThreadName(thread_id, thr->metaObject()->className());
                else
                    setCurrentThreadName(thread_id, objectName.toLocal8Bit());
            }
    #endif
    
            emit thr->started(QThread::QPrivateSignal());
    #if !defined(Q_OS_ANDROID)
            pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
            pthread_testcancel();
    #endif
            thr->run();
        }
    #ifndef QT_NO_EXCEPTIONS
    #ifdef __GLIBCXX__
        // POSIX thread cancellation under glibc is implemented by throwing an exception
        // of this type. Do what libstdc++ is doing and handle it specially in order not to
        // abort the application if user's code calls a cancellation function.
        catch (const abi::__forced_unwind &) {
            throw;
        }
    #endif // __GLIBCXX__
        catch (...) {
            qTerminate();
        }
    #endif // QT_NO_EXCEPTIONS
    
    

    I tried to build QT/Android on Windows with -DQT_NO_EXCEPTIONS, but got the following error:

    ....\include\QtXmlPatterns\5.11.1\QtXmlPatterns/private/../../../../../src/xmlpatterns/utils/qpatternistlocale_p.h:275:2: error: #error "Patternist uses exceptions and cannot be built without."


  • Lifetime Qt Champion

    Hi,

    IIRC, the former will trigger the generation the latter. If you don't use it, you can also skip building the QtXmlPatterns module.



  • @SGaist Hi!

    I built QT without QtXmlPatterns, but it is not clear enough what to use -no-exceptions or -DQT_NO_EXCEPTIONS.


  • Lifetime Qt Champion

    AFAIK -no-exceptions when configuring Qt and QT_NO_EXCEPTIONS when you want to be able to provide both version within your code.



  • @SGaist I succeeded with QT_NO_EXCEPTIONS, now there is no "try {} catch (...)" in qtbase\src\corelib\thread\qthread_unix.cpp, but If I do

    configure.bat -prefix C:\Qt\Qt5.11-Android -no-exceptions -release -force-debug-info -platform win32-g++ -opengl es2 -xplatform android-g++ -android-ndk C:\Users\D-Ef\AppData\Local\Android\Sdk\ndk-bundle -android-sdk C:\Users\D-Ef\AppData\Local\Android\Sdk -opensource -confirm-license -nomake tests -nomake examples
    

    with QT 5.11.1, I get:

    ERROR: Unknown command line option '-no-exceptions'.
    

  • Lifetime Qt Champion

    Getting old... I forgot that it was an option for Qt 4 when not all compilers supported exceptions which is not the case anymore.


Log in to reply