QSerialport
-
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 againstQt5Serialportd.lib
. If I link againstQt5Serialport.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! -
Then please mark this topic as solved :)
Yes - mixing different MSVC runtimes do not work out - it's a pity. -
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?
-
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?
@Christian-Ehrlicher
My Qt libraries were obtained by installingqt-opensource-windows-x86-5.12.9.exe
.
In Visual Studio 2017, I only link eitherQt5Serialport.lib
orQt5Serialportd.lib
in the input libraries.
In Debug mode, I link againstQt5Serialportd.lib
. -
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?
@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. -
Then please mark this topic as solved :)
Yes - mixing different MSVC runtimes do not work out - it's a pity. -
-
Then please mark this topic as solved :)
Yes - mixing different MSVC runtimes do not work out - it's a pity.@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-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... :)
@JonB It mostly works as long as you do the allocation and deallocation with the same runtime.
-
@JonB It mostly works as long as you do the allocation and deallocation with the same runtime.
@Christian-Ehrlicher
Trying to recall now. I did something about defining a macro to make the Release compile still call the debugmalloc()
, it is (was) something likemalloc_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)!