Tag Archives: qt

[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

[solution]

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;
}
file.close();

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‘

problem

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

reason

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)

decided

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

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

catalogue

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.

 

Error when using OpenCV: use of unclared identifier ‘CV_ Bgr2rgb ‘solution

catalogue

1. Error message:

2. Analysis:

3. Solution:

1. Error message:

F:\test\Qt-Demo\mainwindow.cpp:55: error: use of undeclared identifier ‘CV_ BGR2RGB’

2. Analysis:

Because opencv is used   CV_ Bgr2gray did not declare it. Therefore, an undeclared identifier is prompted.

3. Solution:

Reference the following code in the header file:

#include < opencv2\imgproc\types_ c.h>

[Solved] Qt Vtk wglMakeCurrent failed in MakeCurrent(), error: The handle is invalid.

Problem description

The qvtkwidget control is used in QT’s interface. When clicking the close button in the upper right corner of the window, an error is reported: wglmakecurrent failed in makecurrent(), error: the handle is invalid .

Solution:

By overriding the void closeevent (qcloseevent * event) function, manually delete all qvtkwidget type controls, and then close the window.

Example

The qvtkwidget type controls in the QT design interface are as follows:

mymainwindow. H

class MyMainWindow : public QMainWindow
{
    Q_OBJECT
public:
    MyMainWindow(QWidget *parent = Q_NULLPTR);
protected:
	void closeEvent(QCloseEvent *event); 
private:
    Ui::MainWindow ui;
};

mymainwindow.cpp

MyMainWindow::MyMainWindow(QWidget *parent): QMainWindow(parent)
{
    ui.setupUi(this);
}

void MyMainWindow::closeEvent(QCloseEvent *event) {
	delete ui.qvtkWidget;
	delete ui.qvtkWidget_2;
	delete ui.qvtkWidget_3;
	delete ui.qvtkWidget_4;
	event->accept();
}

Postscript

I don’t know whether such hasty delete processing will cause other problems. I hope you can make more corrections.

error: unknown type name ‘Q_DECLARE_METATYPE‘

Recently, when developing with QT4, there was a problem that Q could not be recognized_ DECLARE_ The error code of the metatype macro was transplanted from Qt5. I thought it was not supported by QT4. After checking later, I found that the qmetatype. H header file must be included in QT4, and only qvariant needs to be included in Qt5.