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. QSerialport
Forum Updated to NodeBB v4.3 + New Features

QSerialport

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 457 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.
  • G Offline
    G Offline
    gz_zxh
    wrote on last edited by
    #1
    QStringList LaserVisionIO::getAllSerialPort()
    {
        QStringList portList;
        const auto serialPortInfos = QSerialPortInfo::availablePorts();
    
        for (const QSerialPortInfo &info : serialPortInfos)
        {
            portList.append(info.portName());
        }
        return portList;
    } 
    
    void LaserVisionIO::on_btnStart_clicked()
    {
        QStringList strComs = getAllSerialPort();
    
        qDebug() << __LINE__ << __func__ << "strComs : " << strComs;
    }
    

    When executing the above code, specifically when the getAllSerialPort function finishes, in Visual Studio 2017 Debug mode, an assertion failure occurs. The assertion failure happens at the following code:

    template <typename T>
    Q_OUTOFLINE_TEMPLATE void QList<T>::dealloc(QListData::Data *data)
    {
        node_destruct(reinterpret_cast<Node *>(data->array + data->begin),
                      reinterpret_cast<Node *>(data->array + data->end));
        QListData::dispose(data);
    }
    

    If I use Qt Creator with the same compiler (MSVC 2017), whether in Debug or Release mode, this issue does not occur.

    Of course, it is possible to modify the code to avoid this error, but I believe my current code is correct. Why does this exception happen?
    I am linking against Qt5Serialportd.lib. If I link against Qt5Serialport.lib instead, a different assertion failure occurs, as shown below:

    _CRT_SECURITYCRITICAL_ATTRIBUTE
    void __CRTDECL operator delete(void* const block) noexcept
    {
        #ifdef _DEBUG
        _free_dbg(block, _UNKNOWN_BLOCK);
        #else
        free(block);
        #endif
    }
    

    My Qt version is 5.12.9.
    This is my first time seeking help on a forum. I hope to find some experienced developers who can provide guidance. Thank you very much!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #5

      Then please mark this topic as solved :)
      Yes - mixing different MSVC runtimes do not work out - it's a pity.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      JonBJ 1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        You are mixing debug and release libraries - this does not work with msvc. Compile all libs with the same configuration. How did you get QSerialport?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        G 2 Replies Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          You are mixing debug and release libraries - this does not work with msvc. Compile all libs with the same configuration. How did you get QSerialport?

          G Offline
          G Offline
          gz_zxh
          wrote on last edited by
          #3

          @Christian-Ehrlicher
          My Qt libraries were obtained by installing qt-opensource-windows-x86-5.12.9.exe.
          In Visual Studio 2017, I only link either Qt5Serialport.lib or Qt5Serialportd.lib in the input libraries.
          In Debug mode, I link against Qt5Serialportd.lib.

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            You are mixing debug and release libraries - this does not work with msvc. Compile all libs with the same configuration. How did you get QSerialport?

            G Offline
            G Offline
            gz_zxh
            wrote on last edited by
            #4

            @Christian-Ehrlicher
            Thank you, I understand your point. I did have other libraries mixed between Debug and Release. After I unified all to use Debug mode libraries, the problem no longer occurs.

            1 Reply Last reply
            2
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Then please mark this topic as solved :)
              Yes - mixing different MSVC runtimes do not work out - it's a pity.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              JonBJ 1 Reply Last reply
              0
              • G gz_zxh has marked this topic as solved on
              • Christian EhrlicherC Christian Ehrlicher

                Then please mark this topic as solved :)
                Yes - mixing different MSVC runtimes do not work out - it's a pity.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #6

                @Christian-Ehrlicher said in QSerialport:

                Yes - mixing different MSVC runtimes do not work out - it's a pity.

                15+ years ago, when compilation/execution/debugging times were "slow" and I needed to "optimize" during development, I somehow managed to make it under MSVC so I could compile some modules debug and others not and they would work together OK against debug MSVC runtimes. But of course I cannot remember how... :)

                Christian EhrlicherC 1 Reply Last reply
                0
                • JonBJ JonB

                  @Christian-Ehrlicher said in QSerialport:

                  Yes - mixing different MSVC runtimes do not work out - it's a pity.

                  15+ years ago, when compilation/execution/debugging times were "slow" and I needed to "optimize" during development, I somehow managed to make it under MSVC so I could compile some modules debug and others not and they would work together OK against debug MSVC runtimes. But of course I cannot remember how... :)

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @JonB It mostly works as long as you do the allocation and deallocation with the same runtime.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  JonBJ 1 Reply Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    @JonB It mostly works as long as you do the allocation and deallocation with the same runtime.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #8

                    @Christian-Ehrlicher
                    Trying to recall now. I did something about defining a macro to make the Release compile still call the debug malloc(), it is (was) something like malloc_dbg() and linked always with the debug malloc runtime. Then they were good working together, and I could still compile and run debugger with some "interesting" modules compiled for debug and "uninteresting" ones for release. And we (shared code) only had to compile all the "base" modules once for release only, when they changed, and could still use them with "high level" code code compiled for debug. Time to recompile was slow (large projects)!

                    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