Purpose
I want to batch write controls into a layout. Qlabel and QWidget have about 20. It’s too hard to write line by line.
Qt Debug Assertion Failed! Error reporting reason
It is estimated that it is a wild pointer or a memory leak, because I often have the problem of memory access out of bounds when I use an array. As shown in the figure:
My error code
QVBoxLayout* layout = new QVBoxLayout;//new creates a layout
QLabel* labels = new QLabel[3];// here new an array of three QLabels;
QStringList qstrList;
qstrList<<u8 "Event list" << u8 "Assessment criteria" <<u8 "Subject list";//three strings
for(int i = 0; i<3;i++){
labels[i].setText(qstrList.at(i));//QLabel set text
//---- set Qss----
//---- set the font ----
}
for(int i = 0;i<3;i++){
layout->addWidget(&labels[i]);//add QLabel to the layouts
}
If it can be displayed, an error will be reported on the X of the closed window at the point, as shown in the figure:
My labels variable is not a member variable, which does not involve the problem of destruct before closing the window. If you change release to close the window, the word program abnormal end will also appear.
My solution
I’m used to using C + + arrays before. It’s better to replace QT batch setting components with containers such as qvector and qlist. Resolved Code:
QVBoxLayout* layout = new QVBoxLayout;//new has a layter
QVector<QLabel*> labels(3);//1. Now I know I have to use three so I limited it to three to prevent memory copies. You can also try the QList container
//2. The type in the container can't be a component, only a pointer to a component.
QStringList qstrList;
qstrList<<u8 "EventList" << u8 "Assessment Criteria" <<u8 "SubjectList";//three strings
for(int i = 0; i<3;i++){
QLabel* label = new QLabel(qstrList.at(i));
//---- set Qss----
//---- set the font ----
labels.append(label);
}
for(int i = 0;i<labels.size();i++){
layout->addWidget(labels.at(i));
}
Close the window again and there will be no error. I think the previous error report is the cause of the layout. I saw qtcreate warn me not to use the new control array.
Read More:
- [Solved] Qt Error: qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
- Debug Error: Failed to fetch current robot state [How to Solve]
- [TensorRT] INTERNAL ERROR: Assertion failed: mem = nullpt
- Eclipse’s debug mode failed to start
- [Solved] Failed assertion: line 3180 pos 12: ‘debugNeedsPaint‘: is not true
- [Solved] Unity Error: Assertion failed on expression: ‘IsMatrixValid(matrix)‘…
- [Solved] validateNewTexture:89: failed assertion `BytesPerRow of a buffer-backed texture with pixelFormat
- [Solved] OpenCv5 error: (-215:Assertion failed) !_descriptors.empty() in function ‘add‘
- Klee Error: Assertion `userMainFn && “unable to get user main“‘ failed
- [Solved] Phone Debug Program Error: The application could not be installed: INSTALL_FAILED_TEST_ONLY
- [Solved] Message from debugger: debug-server is x86_64 binary running in translation, attached failed.
- [Solved] flutter Project Error: ScrollController attached to multiple scroll views, Failed assertion: line 109 pos 12
- [Solved] QT error: the packaged exe of Enigma virtual box reports an error cannot load library qt5core.dll
- QT Error: Failed to create vertex shader [Three Methods to Fix]
- error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow‘
- [Solved] Qt UpdateLayeredWindowIndirect failed for ptDst Error
- [Solved] Qt Vtk wglMakeCurrent failed in MakeCurrent(), error: The handle is invalid.
- [Solved] validateRenderPassDescriptor:xxx: failed assertion XXX
- [Solved] Opencv Error: Error: Assertion failed (data) in cv::Mat::at, file … mat.inl.hpp, line 897(Accessed pixels of non-existent matrix)
- [Solved] PySide2 Error: This application failed to start because no Qt platform plugin could be initialized