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. What is the difference between configuring QT with -no-exceptions and -DQT_NO_EXCEPTIONS?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.4k Views
  • 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.
  • D Offline
    D Offline
    Dmitriano
    wrote on last edited by Dmitriano
    #1

    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."

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

      Hi,

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

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

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

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

        D Offline
        D Offline
        Dmitriano
        wrote on last edited by
        #3

        @SGaist Hi!

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

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

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

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

          D 1 Reply Last reply
          2
          • SGaistS SGaist

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

            D Offline
            D Offline
            Dmitriano
            wrote on last edited by Dmitriano
            #5

            @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'.
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by SGaist
              #6

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

              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
              1

              • Login

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