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. [SOLVED] Shared library, segmentation fault, QWinEventNotifier, QSerialPort
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Shared library, segmentation fault, QWinEventNotifier, QSerialPort

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.2k 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.
  • C Offline
    C Offline
    cidadao
    wrote on last edited by
    #1

    Hello,

    Im developing a GUI app where I use a shared library (.dll) that I created using the same toolchain (QtCreator 2.8.0 and Qt5.1). Im also using QSerialPort to communicate with external hardware (which Im also developing). In summary, the shared library is responsible to communicate with the hardware and, by parsing the incomming data, store the board information on the Board class. However, whenever I access a Board object/instance, either to set or get data, I have a segmentation fault.
    The strange thing is that selBoard (as in the example below) is never NULL, but on the qDebug line I get:
    *selBoard QWinEventNotifier(0x28f0558) *

    How can that be? If I never access Board instances (get/set private variables) I never get segmentation fault. Also, I don't have any issues on creating Board instances.
    I'm not using threads, just the signals and slots mechanism (for example, on QSerialPort I use readyRead()) but it seems a concurrency issue. Or maybe just a bug somewhere in Qt5.1 or the new QSerialPort class? Ahh, I don't know. Any help is greatly appreciated!

    @
    Board *selBoard = 0;

    switch(id)
    {
    case etID_Gateway:
        selBoard = m_conn->gateway();
        break;
    case etID_Device:
        selBoard = m_selNode->device();
        break;
    default:
        selBoard = 0;
    }
    
    qDebug() << "selBoard" << selBoard;
    (...) = selBoard->name(); // access selBoard -> segfault!
    

    @

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

      Hi and welcome to devnet,

      Are you sure that m_conn and m_selNode return a valid Board ?

      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
      • C Offline
        C Offline
        cidadao
        wrote on last edited by
        #3

        (deleted)

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cidadao
          wrote on last edited by
          #4

          [quote author="SGaist" date="1376764989"]Hi and welcome to devnet,

          Are you sure that m_conn and m_selNode return a valid Board ?[/quote]

          Yep. m_selNode and m_conn are not NULL, and the device() method returns a pointer to a Device object (Device*) which is a subclass of Board. Board is a subclass of QObject.
          What I can’t really understand is why selBoard is printed as a QWinEventNotifier on qDebug(). As far as I know QSerialPort is the only class that is using it, so I think the bug may be related to it. But… it just a guess.

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

            I understood those two where not NULL, but what do they return ?

            Also, not NULL (for what m_conn and m_selNode return) doesn't mean that the pointer is valid just that it's not 0. And what you are getting printed seems to confirm that the pointer is not what you are waiting.

            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
            • C Offline
              C Offline
              cidadao
              wrote on last edited by
              #6

              Thank you very much, you made my day :) The pointer the device() method was returning was in fact invalid. Problem: private variable not previously initialized. I was expecting to be 0 the first time I call this method.

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

                You're welcome !

                Don't have such expectation with C/C++, especially for pointers. Always initialize them at 0 and the other variables to sensible values.

                If it's all working now, please update your thread's title to solved so other forum users may know a solution has been found :)

                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