Tag Archives: qt

[Solved] Qt UpdateLayeredWindowIndirect failed for ptDst Error

Error encountered when setting QT window transparent shaded border:

The widget used in the code implementation is embedded with a frame, and the white background and fillet style settings are set for the frame

Then directly call the setgraphicseffect method on the widget to add the shadow effect, and the above error occurs.


Remove the shadow setting of the widget and directly set the shadow on the frame, UI -> frame-> Setgraphicseffect calls shadow.

After testing, the above error printing will not appear again.

C++:error C2872: ‘byte‘: ambiguous symbol [How to Solve]

The reason is to merge two project programs written by others. There is no problem with separate testing. After merging, compile and report errors

After searching the data, it is suspected that it is related to the header file windows.H

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <windows.h> // Commented out to compile properly
#include <map>
#include <any>

My solution is to #include <windows.h> comment it out (the header file is not used in the code), and then it can run successfully. I didn’t delve into the specific reasons, mainly by referring to the reference materials at the end of the article.

[Solved] QT Warning: Slots named on_foo_bar are error prone

Problem phenomenon:

this warning appears because when processing the signal slot relationship, we use “go-to slot” in the UI designer to make the program generate automatically
the weakness of this automatic generation is that one day, you may change the name of the control in the UI designer, but the compilation will not report an error. The program still runs normally, and the compilation does not prompt errors
in this way, the control is equivalent to not being connected to the slot function and becomes invalid.

Recommended solution:
recommendation 1: do not automatically generate signal slot connection through “go to slot” of UI designer. The relationship can be established manually. For example:
connect (toolbutton, & QPushButton:: clicked,
this, & yourclassname:: nameofyourslot)
recommendation 1: ignore this warning and just ignore it. Because this is just a kind reminder.

[Solved] PySide2 Error: This application failed to start because no Qt platform plugin could be initialized

PySide2 Error: This application failed to start because no Qt platform plugin could be initialized
Add at the first:

import sys,os
import PySide2
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path

How to Solve QT error: LNK1158: Cannot Run “rc.exe”

[problem description]

Qt5.9.11 is installed on windows10, and the compilation error is: error: lnk1158: unable to run “RC. Exe”

[problem location]

The path of rc.exe is not put into the environment variable


Add the path “C:\program files (x86)\windows kits\8.1\bin\x86” to the environment variable path.

Restart qtcreator and the compilation is successful.

Vs2019 + QT parses the XML file and reports an error at doc.setcontent (& file)

Vs2019 + QT parses the XML file and reports an error at doc.setcontent

Made a very low-level mistake. Record the process.

A QT project was established long ago. Now to add a function of parsing XML files using the qdom class, there is always an error in the sentence doc.setcontent (& amp; file) , and there is no error message. The relevant C + + codes are as follows:

QString error;
int line, column;
if (doc.setContent(&file, &error, &line, &column)) {
    qDebug() << doc.toString(4);
else {
    qDebug() << "Error:" << error << "in line " << line << "column" << column;

When doc.setcontent (& amp; file, & amp; error, & amp; line, & amp; column) , critical error detected c00000374 is displayed

The first reaction is that the XML file is incorrectly written. For example, there is no space in the space, Chinese punctuation is entered, or the two sides of the tag are inconsistent
after repeatedly confirming that the XML file is correct, the stackoverflow search said that the relative path cannot be used, but the absolute path must be used… Another attempt of the absolute path is useless.

Create a new project and run it with the same code without error. Through careful comparison, it is found that in the new project, I added the XML class library

but not in the original project!

So far, add $(qtdir) \ include \ qtxml in the C/C + + include directory, add qt5xmld.lib [debug mode] and qt5xml. Lib [release mode] in the linker, and the operation is successful!

Finally, I found that if the XML file is written incorrectly, the above program can locate the error location. Direct reporting of fatal error/critical error or unresolved external symbols like this__ declspec(dllimport) public: __ Cdecl , the probability is that the Lib file link is wrong rather than the code problem. You need to check whether the environment is configured correctly.

A simple question has been wordy for a long time… Mainly to warn yourself that you must think more and think more about ways to expose the problem when you encounter a problem that has no solution on the Internet!

Pyqt5 Error: AttributeError: ‘QWidget‘ object has no attribute ‘setCentralWidget‘


AttributeError: 'QWidget' object has no attribute 'setCentralWidget'


We can see setcentralwidget in QT help document that it belongs to the method of qmainwindow class and is defined separately in its class, so it cannot be called directly for its parent class QWidget.

void QMainWindow::setCentralWidget(QWidget *widget)


Write QtWidgets.QWidget() converts QtWidgets.QMainWindow().

Error encountered during QT + opencv compilation: file not recognized: file format not recognized error resolution


1. Error message:

2. Analysis  

3. Solution

1. Error message:

D:\InstallSoftware\opencv\OpenCV-MinGW-Build-OpenCV-4.5.2-x64\x64\mingw\bin\libopencv_ calib3d452.dll:-1: error: file not recognized: File format not recognized

2. Analysis  

This is because the opencv compiled file version is different from the QT project version. You should choose the correct version of the toolkit.

3. Solution

For example, my opencv compilation file is opencv build_ 64 bit, then select MinGW 64 bit for the project.