Tag Archives: qt

error: undefined reference to `calculate()` [How to Solve]

Error Messages:

error: undefined reference to `calculate()`

 

When calling functions in xx.h and xx.c, such as calculate()
are as follows:

#include "xx.h"
int t;
int result = calculate(t);

An error is reported at this time:

error: undefined reference to `calculate()`

 

Solution:

Modify xx.c to xx.cpp, it will be OK!
Guessing that a direct call to xx.h in Qt may not find the definition in xx.c, but only the definition in xx.cpp can be recognized.

[Solved] error: invalid operands of types ‘QLabel*‘ and ‘void‘ to binary ‘operator>

Error in QT: invalid operators of types’ qlabel * ‘and’ void ‘to binary’ operator & gt; ‘ Wrong solution.

This kind of error is generally the operation symbol use error

For example:

btnLabel>setFixedSize(menuBtn->width(),menuBtn->height());

Here ‘>’ operation symbol is wrong, changed to ‘->’, it will be OK!

 btnLabel->setFixedSize(menuBtn->width(),menuBtn->height());

[Solved] ninja: error: build.ninja:1802: multiple rules generate Debug/xxx.exe [-w dupbuild=err]

Error Messages:

— Configuring done
— Generating done
CMake Error:
Running    ‘D:/Qt/Tools/Ninja/ninja.exe’ ‘-C’ ‘D:/code/build-EFR-linux247-Debug’ ‘-t’ ‘recompact’   failed with:    ninja: error: build.ninja:1802: multiple rules generate Debug/xxx.exe [-w dupbuild=err]

Cause:
Duplicate multiple targets
CMAKE If the specified target is the same as the target path automatically generated by qt, this problem will occur
Solution:
Modify the target path

Failed to find Qt component “Widgets“ [How to Solve]

In the project, QT6 is used 2.1 after installing QT, this error is reported when QtCreator is used:

but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
  FOUND.  Reason given by package:

  Failed to find Qt component "Widgets" config file at ""

The reason is that although QT has been installed, some other libraries QT depends on have not been installed:

I use Ubuntu system: use the following command to install (OpenGL installation)

sudo apt-get install build-essential libgl1-mesa-dev

[Solved] QT Icon Set Error: error: [release/helloworld_resource_res.o] Error 1

When learning QT setting icons for beginners, errors are reported during compilation. The following two error correction methods and correct correction methods are shared.

Error operation 1: modify the suffix of JPG file to .ico

Error operation 2: save as using PS and other tools on BMP format and then modify the suffix to .ico format

Correct operation: generate transparent ICO icons online through ICO, and then import them

Tips: the default size of qtball is 32 * 32, and the menu is 16 * 16

If the icon size is larger than the default size, QT will automatically reduce the size; If the icon size is smaller than the default size, QT will not operate.

.ico files need to be placed in the project resource directory.

Compiled, as shown below.

How to Solve QML Settings Error (QML FileDialog)

When we want to use the file dialog box in the interface, we can use the FileDialog component with the following code:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Dialogs 1.3

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("")
    
    Button {
        id:openFile
        text: qsTr("Open the Files")
        backgroundDefaultColor: "#5A6268"
        onClicked:  {
            fileDialog.open()
        }
    }

    FileDialog {
        id: fileDialog
        title: qsTr("Please choose a file")
        nameFilters: ["Photo Files", "Image Files (*.jpg *.png *.gif *.bmp *.ico)", "*.*"]
        onAccepted: {
            _filePath.text = String(fileUrl)
            var filepath = new String(fileUrl)
        }
    }
}

Error Message:

file:///D:/Qt/Qt5.12.6/5.12.6/msvc2017_64/qml/QtQuick/Dialogs/DefaultFileDialog.qml:102:33: QML Settings: Failed to initialize QSettings instance. Status code is: 1
file:///D:/Qt/Qt5.12.6/5.12.6/msvc2017_64/qml/QtQuick/Dialogs/DefaultFileDialog.qml:102:33: QML Settings: The following application identifiers have not been set: QVector("organizationName", "organizationDomain")

 

Solution:
Add a line of code to the main function of main.cpp.

QCoreApplication::setOrganizationName("appName.org");//appName.org can be set at will

[Solved] The “QtRunWork“ task returned false but did not log an error

Recently in business development need to update the UI in the QThread, if the UI handle through the direct update will make the program reported an error, because the update of the UI in the thread will not be captured by the original thread of the EXEC event, will lead to message event blockage generated ERROR, so the use of the signal and slot mechanism, and then I declared a signals signal in the QThread, the compilation reported this error.

The "QtRunWork" task returned false but did not log an error

No detailed warning was given, and I later checked the relevant QT instructions to solve the problem.

Solution: Add a line of macro definition to the class where you use signals and slots.

Q_OBJECT

This will work, the signal and slotted based on Q_OBJECT, we need to declare it module to our class so that the QT compiler can instantiate it, otherwise it will be exception ERROR.

Main Use connect Error: without object [How to Solve]

//mytest::mytestShowChanged Note that the function cannot be added (), otherwise an error is reported: C:\Users\xutie\Desktop\qtthread\main.cpp:36: error: cannot call member function 'void mythread1::mythread1show()' without object
QObject::connect(&mytest1,&mytest::mytestShowChanged(),&mythread1Object1,&mythread1::mythread1show());

Modify as:
QObject::connect(&mytest1,&mytest::mytestShowChanged,&mythread1Object1,&mythread1::mythread1show);

QT calls the API of ffmpeg error [How to Solve]

QT calls the API of ffmpeg, and the error is as follows:

These two errors are caused by the lack of dynamic libraries in the running directory,

Dynamic library:

Program running Directory:

Directly copy all DLLs to the running directory.

QT calls ffmpeg API with the following configuration:

1. This document

Put in the project directory

2. Import and store files and header files

3. Add corresponding header file

4. Copy a dynamic library in the running directory

[Solved] QT error: error: undefined reference to ` VTable`

Question:

QT compilation error:

error: undefined reference to `vtable ...`

 

reason:

1.Qt uses signals and slots to implement communication features.
2.Signals and slots can be used when the class is derived from QObject and the Q_OBJECT macro is added to the header file.
3.When Q_OBJECT is added to the class header file QtCreator will automatically create a moc_***.cpp file that implements the code for signal and slot communication.
4.However, sometimes when we create a class through QtCreator without selecting the IDE option to derive it from the QObject class, but add it later, QtCreator will not automatically create the moc_***.cpp file. In this case it will report an error: undefined reference to `vtable for ***.

 

Solution:

According to various online methods, it can not be solved, nor can rebuild
mine is a small project. Just delete the build-XXX folder and rebuild it.