Tag Archives: qt

The. Exe crashed program ends abnormally when the QT project is copied to the new environment

Tip: if the project has been successfully compiled and run on a computer, the code of the project itself is OK

Based on such preconditions, the problem should be directly located in the direction of environment configuration.

The third-party library I use this time is opencv:

        1. Include the opencv path in the project pro file and add the corresponding library file

INCLUDEPATH += D:/openCV/opencv/build/include

LIBS += D:/openCV/opencv/build/x64/vc15/lib/opencv_world451.lib
LIBS += D:/openCV/opencv/build/x64/vc15/lib/opencv_world451d.lib

        2. Find the corresponding. DLL file from the opencv installation path and copy it to the running program path generated by the project

     

The solution of white screen crash when loading QML

1 reference link

qt – Rectangle element is not displayed – Stack Overflow

(122 messages) when QML starts on the development board, a white screen appears (two loading modes of QML)_ xi__ Q’s column CSDN blog

(122 messages) about the solution to the problem that the stackview cannot be displayed (white screen) on the target machine (customized Ubuntu) when QML is migrated from Ubuntu development_ Changsha red fat network technology (original name: Red Imitation workshop) – CSDN blog

2 best practices

main.cpp

#include <QGuiApplication>
#include <QQuickView>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQuickView engine(QUrl(QStringLiteral("qrc:/main.qml")));
    engine.show();

    return app.exec();
}

Master.qml

import QtQuick 2.0

Rectangle {
    width: 100
    height: 100
    color: "red"
}

Setting the exclutable path of QT running settings

1. Build directory and source code directory are at the same level
2. After the build directory of build is selected, the directory of exclutable is automatically assigned to the debug or release file
3. The directory of the debug or release file is the same level as the source code
2. The working directory of run is at the same level as the source code directory.

How to Use qdbusinterface to call DBUS interface

        // Create QDBusInterface
        QDBusInterface iface("org.onboard.Onboard",
                             "/org/onboard/Onboard/Keyboard",
                             "org.onboard.Onboard.Keyboard");
        if (!iface.isValid()) {
            qInfo() << qPrintable(QDBusConnection::sessionBus().lastError().message());
        }
        QDBusReply<void> reply = iface.call("Show");
        if (reply.isValid()) {
            qInfo() << "call org.onboard.Onboard.Keyboard success";
            return;
        }
        qInfo() << "call corg.onboard.Onboard.Keyboard failed" << reply.error();
    });

[Solved] Ubuntu pyinstaller Error when packaging executable file: … qt.qpa.plugin: Could not find the Qt platform plugin “xcb“ in “…

Ubuntu pyinstaller Error when packaging the executable: … qt.qpa.plugin: Could not find the Qt platform plugin “xcb” in “…
Solution to the problem


Problem
Ubuntu pyinstaller reports an error when packaging the executable: .QFactoryLoader::QFactoryLoader() checking directory path “/home/dyj/CarUI/dist/carmain/platforms” … qt.qpa.plugin: Could not find the Qt platform plugin “xcb” in “” This application failed to start because no Qt platform plugin could be initialized.
Solution
Add the following code to your own main program code.

import 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

Qt error: no matching function for call to ‘MainWindow::connect(QAction*&, void (QAction::*)

Error in QT compilation:

error: no matching function for call to 'MainWindow::connect(QAction*&, void (QAction::*)(bool), MainWindow* const, MainWindow::MainWindow(QWidget*)::__lambda0)'});

Error reason: QT software version is too low, lower than qt5.4.

Solution: add code to. Pro file:

CONFIG   += C++11

Problem solving.

MySQL driver compiling method of QT under windows and solutions to abnormal errors

2015-11-20

Recently, in the process of compiling QT’s MySQL driver with MinGW under windows, it was compiled through several twists and turns. In the process of compiling, there are many problems. In order to avoid similar errors in the subsequent driver compilation and facilitate the rapid completion of this driver compilation, the compilation methods are sorted out.

This method is illustrated by a case of my own compiling environment.

1、 Compiling environment

Operating system: win7 64 bit

MySQL service version: mysql-5.5.46-win32

QT version: 4.8.6

Compiling environment: MinGW 64 bit

2、 Compilation steps

(1) Generate libmysql. A file

Because MinGW compiler needs to use “. A” suffix static library file to connect with static library, but according to MySQL database, there is only “. Lib” format static library, so it needs to be converted. Two tools are needed for conversion reimp.exe and dlltool.exe The paths of these two tools need to be configured in the path environment variable. The conversion command is as follows:

First of all, open the CMD command input box and enter the Lib path under the MySQL installation path. For example, my path is: “C:// program files (x86)  MySQL  MySQL server 5.5  lib”.

Next, enter the following commands in turn:

reimp -d  libmysql.lib

dlltool -k -d  libmysql.def  -l libmysql.a

After successful execution, you can view the library file of libmysql. A in this path.

(2) Editor mysql.pro Engineering documents

Find it in the installation path of QT mysql.pro The path of my pro file is: “C:// Qt/4.8.6/SRC/plugins/sqldrivers/MySQL”.

open mysql.pro File, add the following configuration below:

INCLUDEPATH+=”C:/ProgramFiles(x86)/MySQL/MySQL Server 5.5/include/”

LIBS+= -L”C:/ProgramFiles(x86)/MySQL/MySQL Server 5.5/lib/” –llibmysql

The second line can also be written as follows:

LIBS+= “C:/ProgramFiles(x86)/MySQL/MySQL Server 5.5/lib/libmysql.a”

Makefile Makefile.Debug 、 Makefile.Release Three makefile files and others. As shown in the figure below:

(3) Edit makefile file

Take the debug version as an example. open Makefile.Debug File, find LIBS = “XXXX” line and modify it. Because there is a problem with this configuration generated.

The original configuration is as follows:

LIBS = -L”c:\Qt\4.8.6\lib”debug\qsqlmysqld_ resource_ res.o -llibmysql “-LC:/ProgramFiles(x86)/MySQL/MySQL Server 5.5/lib/” -llibmysql -lQtSqld4 -lQtCored4

According to our intention, according to makefile’s syntax rules, we can clearly find the problem. First of all, “L” must be placed outside the path of the configuration library. Second, the – llibmysql command has repetition.

It is revised as follows:

LIBS = -L”c:\Qt\4.8.6\lib”debug\qsqlmysqld_ resource_ res.o -L “C:/Program Files(x86)/MySQL/MySQLServer 5.5/lib/” -llibmysql -lQtSqld4 -lQtCored4

Or it can be modified as follows:

LIBS = -L”c:\Qt\4.8.6\lib”debug\qsqlmysqld_ resource_ res.o “C:/Program Files(x86)/MySQL/MySQL Server5.5/lib/libmysql.a” -lQtSqld4 -lQtCored4

The release version of makefile is modified in the same way.

(4) Execute the make command

Use the mingw32 make command to execute makefile. If no parameter is added, it will be executed by default Makefile.Debug . You can write debug or release or both after mingw32 make command to execute the corresponding version of makefile.

For example, execute debug and release makefile at the same time. The command is as follows:

mingw32-make debug release

After successful execution, you can see qsqlmysqld. A qsqlmysqld.dll Two library files, in the release folder, see qsqlmysql. A qsqlmysql.dll Two library files.

These four library files are the static library and dynamic library driven by MySQL of debug and release versions.

(5) Copy the driver file to the specified directory

Copy the four driver files generated in the previous step to the database driver directory of QT, that is, under the path of “C:: (QT) ﹣ 4.8.6 ﹣ plugins ﹣ sqldrivers”.

(6) Copy libmysql.dll File to specified directory

Install the libmysql.dll Copy the dynamic library file to the bin directory of QT, i.e. “C:// Qt/4.8.6/plugins/sqldrivers”. At this point, use QT to write a program to connect to MySQL database.

3、 Test whether the driver is available

Write demo program to test QT driver. The main codes are as follows:

#include <QtCore/QCoreApplication>  

#include <QDebug>  

#include <QStringList>  

#include <QString>  

#include <QSqlDatabase>  

int main(int argc, char *argv[])  

{  

    QCoreApplication a(argc, argv);  

    qDebug()<<“Available drivers:”;  

    QStringList drivers = QSqlDatabase::drivers();  

    foreach(QString driver,drivers)  

    qDebug()<<“\t”<<driver;  

    return a.exec();  

}  

Add in project file

QT       +=sql

Running this demo program, you can see “qmysql3” and “qmmysql” in the list of available drivers. As shown in the figure below:

4、 Common problems and Solutions

(1) Cannot find – llibmysql

“- llibmysql” cannot be found because the configuration in makefile is incorrect. After modifying Makefile, compile it again, and the compilation passes.

The solution to this problem is: check the configuration in Makefile, modify it to conform to the rules of makefile syntax, and then try again.

(2) Undefined reference to ‘MySQL’_ character_ set_ [email protected]

This situation, as well as a series of undefined references related to MySQL, is due to a problem loading the MySQL library. After online query of relevant information, we know that it is the version problem of MySQL database. When using the link library in 64 bit MySQL database, we will report this error.

The solution is to install a 32-bit MySQL database and configure it mysql.pro File, compile the driver again, and the error will not appear again.

(3) Unrecognized command line option \ “- fno keep inline dllexport \”

The reason for this error is that the version of the compiler is relatively low. To query the version of the currently used gcc compiler is GCC – 4.4.0. The explanation of the online information is as follows:

this is because\”-fno-keep-inline-dllexport\” is the option of mingw 4.6.1, but i’musing 4.5. So I change it by installingcodelite-3.5.5377-mingw4.6.1-wx2.9.2.exe

The translation is as follows:

This is because the option “- fno keep inline dllexport” is a function of mingw4.6.1. The current version is too low, so the gcc compiler of version 4.6.1 or above is needed.

Later, the MinGW compiler environment of 4.8.1 version of gcc compiler was installed. When compiling this driver, the above error disappeared.

Therefore, the solution to this problem is to install the gcc compiler above 4.6.1.

Installing qt5.8.0 error reporting during installation process

Error during installation process( qt.tools.perl );Execution failed:Couled not start:”{0,3010,1603,5100} misexec….

The reason for this error is that when installing QT, you select all the installation files (the hard disk is big enough ) and check the strawberry Perl under tools. If you do not check this one, you will have no problem,

In addition, when compiling vs2013 version, it is also possible that the job error 2 may be directly ignored due to the warning dialog box (this is what I did,,).

Strawberry Perl is a Perl programming tool on Windows platform. If you are not a programmer developing/testing Perl programming, and the program you use does not need Perl support, you do not need to install it.

Q & A: http://bbs.csdn.net/topics/392094375

The crash of delete after QT removeitem in qgraphicsscene and the display residue

Problem description

In the process of using QT’s graphicsview framework to create and interact with user-defined items, you need to remove unnecessary user-defined items. However, after the user-defined items interact with the re implemented rotation and scaling, removeitem () + delete will occasionally cause the error of accessing illegal memory, and even if you only use removeitem (), there will occasionally be residual items in the view.

Solutions

Using setitemindex method of qgraphicsscene (qgraphicsscene:: Noindex);
to disable quick query of index can solve the above problem.

other

For the problem of whether to delete after using removeitem(), the official question has given a clear explanation

The ownership of item is passed on to the caller (i.e., qgraphics scene will no longer delete item when destroyed).
remove the item and all its children from the scene. Ownership of the item is passed to the caller (that is, qgraphicsscene will not delete the item when it is destroyed).

So remember to delete