Common mistakes in Qt

There are multiple overloads for signal functions or slot functions.

E.g:

The valueChanged () function has two overloads, so when we use this signal, we need to use a function pointer to explicitly point to one of the functions. E.g:

void (QSpinBox:: *p)(int) = &QSpinBox::valueChanged;

 In this way, p clearly points to the valueChanged function whose parameter is int. This will not cause a signal slot connection error.

Did not execute qmake

Sometimes there will be some undefined or reference errors. At this time you may need to make qmake. There will be no errors. For example, I created a new class, this class does not inherit from these classes. Even if you add the Q_OBJECT macro. You will still encounter error: undefined reference to `vtable for xxxx 'when compiling. At this time, you need to manually make qmake. Right-click your project and execute qmake.

 

The macro Q_OBJECT is written in the CPP file

Qt's moc will automatically process the header file containing Q_OBJECT, and only process the header file. So you wrote Q_OBJECT in the CPP file. You may encounter such an error: "One or more symbols with multiple definitions were found." In Qt, you should not put the function implementation of the class using the library provided by Qt in the header file. This will also cause errors due to the processing of moc.

 

Published 242 original articles · Like 180 · Visits 160,000+

Guess you like

Origin blog.csdn.net/zy010101/article/details/105422437