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. Cathing SEGFAULT
Qt 6.11 is out! See what's new in the release blog

Cathing SEGFAULT

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 5.4k Views 1 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.
  • P Offline
    P Offline
    Polina89
    wrote on last edited by
    #1

    Hello. I have a multithread application. It works fine on many computers but it often crashes on some of them. So I can't find the reason cause it works ok on my own computer and I can't find what leads to SEGFAULT. I decided to log. I found this example
    @void myMessageOutput(QtMsgType type,const QMessageLogContext &context, const QString &msg)
    {
    QByteArray localMsg = msg.toLocal8Bit();
    QFile fMessFile(qApp->applicationDirPath() + "/myProjectLog.log");
    if(!fMessFile.open(QIODevice::Append | QIODevice::Text)){
    return;
    }
    QString sCurrDateTime = "[" + QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz") + "]";
    QTextStream tsTextStream(&fMessFile);
    switch (type) {
    case QtDebugMsg:

    tsTextStream << QString("myProjectLogDebug%1: %2 %3 %4 %5\n").arg(sCurrDateTime).arg(msg).arg(context.file).arg(context.line).arg(context.function);
    break;
    case QtWarningMsg:

    tsTextStream << QString("myProjectLogWarning%1: %2 %3 %4 %5\n").arg(sCurrDateTime).arg(msg).arg(context.file).arg(context.line).arg(context.function);
    break;
    case QtCriticalMsg:

    tsTextStream << QString("myProjectLogCritical%1: %2 %3 %4 %5\n").arg(sCurrDateTime).arg(msg).arg(context.file).arg(context.line).arg(context.function);
    break;
    case QtFatalMsg:

    tsTextStream << QString("myProjectLogFatal%1: %2 %3 %4 %5\n").arg(sCurrDateTime).arg(msg).arg(context.file).arg(context.line).arg(context.function);
    abort();
    }
    }@

    It works perfect with debug messages and I can see them in the log file. But when I call SEGFAULT intentionally to check if the function works as I need, I can see nothing in my log file and I don't get to the breakpoint at line 23. Is there any way to catch SEGFAULT under Windows. I found some other ways only for Linux or MacOS. Or maybe I should do smth completely different to see where my application crashes. Thanx a lot!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      There is not easy to way to identify the segmentation fault. When it fails you can't expect the code to come to your message handler. You can try with C++ exception handling. Still identifying the location of fault is not deterministic.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        You may try to use "segvcatch library":https://code.google.com/p/segvcatch/
        It converts hardware exceptions into c++ exceptions

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Polina89
          wrote on last edited by
          #4

          Thanx a lot! But I read it is not good to use try-catch in Qt, isn't it?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            I think that for your use case it is ok to use try-catch in the main function like it is described "here":http://qt-project.org/doc/qt-5/exceptionsafety.html#recovering-from-exceptions

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

              Hi,

              One thing that might also comes into play, your custom message handler doesn't have any protection for concurrent access

              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
              0

              • Login

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