当前位置:网站首页>QT meta object qmetaobject indexofslot and other functions to obtain class methods attention
QT meta object qmetaobject indexofslot and other functions to obtain class methods attention
2022-07-06 13:43:00 【Jingchu idlers】
- indexOfSlot Return from QObject Index of slot function in derived class , If there is a specified slot function , Then return to non -1 Value , If it doesn't exist , Then return to -1.
indexOfMethod Return from QObject Index of any function of derived class , If there is a specified function , Then return to non -1 Value , If it doesn't exist , Then return to -1.
indexOfSignal Return from QObject Index of any signal of derived class , If there is a specified signal , Then return to non -1 Value , If it doesn't exist , Then return to -1.
The following for QtWidgetsApplication2.h:
#pragma once
#include <QtWidgets/QWidget>
#include "ui_QtWidgetsApplication2.h"
#include"test.h"
class QtWidgetsApplication2 : public QWidget
{
Q_OBJECT
signals:
void setValueSignal(int);
void testSignal(int&);
public slots:
int setMyAge(int&);
int setValue(int nValue);
int setValue(int* pValue);
void setColor(const QColor& clr);
void setTest(const CTest& test);
public:
QtWidgetsApplication2(QWidget *parent = Q_NULLPTR);
private:
Ui::QtWidgetsApplication2Class ui;
};
QtWidgetsApplication2.cpp Document code omitted . The following for test.h
#pragma once
class CTest
{
public:
CTest() {};
~CTest() {};
};
The following for main:
#include "QtWidgetsApplication2.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtWidgetsApplication2 w;
auto nIndex1 = w.metaObject()->indexOfSlot("setValue(int)");
auto nIndex2 = w.metaObject()->indexOfSlot("setMyAge(int&)");
auto nIndex3 = w.metaObject()->indexOfSlot("setValue(int*)");
auto nIndex4 = w.metaObject()->indexOfSlot("setColor(QColor)");
auto nIndex5 = w.metaObject()->indexOfSlot("setTest(CTest)");
qDebug() << "nIndex1:" << nIndex1 << "nIndex2:" << nIndex2
<< "nIndex3:" << nIndex3 << "nIndex4:" << nIndex4
<< "nIndex5:" << nIndex5 << "\r\n";
auto nIndex6 = w.metaObject()->indexOfSlot("int setValue(int)");
auto nIndex7 = w.metaObject()->indexOfSlot(" setValue(int)");
auto nIndex8 = w.metaObject()->indexOfSlot("setValue(int )");
auto nIndex9 = w.metaObject()->indexOfSlot("setValue(int value)");
qDebug() << "nIndex6:" << nIndex6 << "nIndex7:" << nIndex7
<< "nIndex8:" << nIndex8 << "nIndex9:" << nIndex9 << "\r\n";
auto nIndex10 = w.metaObject()->indexOfSlot("setColor(const QColor)");
auto nIndex11 = w.metaObject()->indexOfSlot("setColor(QColor&)");
auto nIndex12 = w.metaObject()->indexOfSlot("setColor(const QColor&)");
auto nIndex13 = w.metaObject()->indexOfMethod("setValue(int)");
auto nIndex14 = w.metaObject()->indexOfMethod("dansir(int)");
qDebug() << "nIndex10:" << nIndex10 << "nIndex11:" << nIndex11
<< "nIndex12:" << nIndex12 << "nIndex13:" << nIndex13
<< "nIndex14:" << nIndex14 << "\r\n";
auto nIndex15 = w.metaObject()->indexOfSignal("setValueSignal(int)");
auto nIndex16 = w.metaObject()->indexOfSignal("setValueSignal(int )");
auto nIndex17 = w.metaObject()->indexOfSignal("testSignal(int&)");
qDebug() << "nIndex15:" << nIndex15 << "nIndex16:" << nIndex16
<< "nIndex17:" << nIndex17 << "\r\n";
w.show();
return a.exec();
}
The input results on my machine are as follows :

From the above input results , Summarized below :
- The parameters of these functions pass in the function or signal to be searched , It does not include the return value of function or signal , Otherwise it will return to -1, Such as : The first 18 Line .
- The parameters of these functions pass in the function or signal to be searched , And there must be no space between the function name and double quotation marks , Otherwise it will return to -1, Such as : The first 19 Line .
- The parameters of these functions pass in the function or signal to be searched , If there is a parameter type , Then there must be no space between the parameter type and the parentheses , Such as : The first 20 Line .
- The parameters of these functions pass in the function or signal to be searched , You can take parameter types , But no specific parameter name , Such as : The first 21 Line .
- The parameters of these functions pass in the function or signal to be searched , If the parameter is a reference and the parameter type is not int、double Basic data types such as , Then remove the reference symbol , Such as :setColor(QColor&) Returns the -1, Need to put setColor(QColor&) Change it to setColor(QColor), If the parameter has const, Will return to -1, Need to put const Get rid of , namely setColor(const QColor&) Should be changed to setColor(QColor).
Sum up : These three indexOf The parameters of the first function are :
- Function or signal name to search .
- Function or signal names cannot have return values .
- If the function or signal name has parameters , Only parameter types can be taken , No specific parameter name .
- If the function or signal name has parameters , There cannot be spaces between parameter types and braces .
- There must be no space between the function or signal name and the double quotation marks .
- Non basic data type const Or the quotation should be removed .
边栏推荐
- [during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
- JS interview questions (I)
- [modern Chinese history] Chapter V test
- 1.C语言矩阵加减法
- canvas基础2 - arc - 画弧线
- 最新坦克大战2022-全程开发笔记-2
- 优先队列PriorityQueue (大根堆/小根堆/TopK问题)
- 编写程序,模拟现实生活中的交通信号灯。
- Mortal immortal cultivation pointer-2
- 2.初识C语言(2)
猜你喜欢

深度强化文献阅读系列(一):Courier routing and assignment for food delivery service using reinforcement learning

(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。

The latest tank battle 2022 - Notes on the whole development -2

凡人修仙学指针-1

Arduino+ water level sensor +led display + buzzer alarm

The latest tank battle 2022 full development notes-1

There is always one of the eight computer operations that you can't learn programming

3.C语言用代数余子式计算行列式

Mode 1 two-way serial communication is adopted between machine a and machine B, and the specific requirements are as follows: (1) the K1 key of machine a can control the ledi of machine B to turn on a

C language to achieve mine sweeping game (full version)
随机推荐
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
Differences among fianl, finally, and finalize
Mortal immortal cultivation pointer-1
string
8. C language - bit operator and displacement operator
抽象类和接口的区别
一段用蜂鸣器编的音乐(成都)
最新坦克大战2022-全程开发笔记-3
Implement queue with stack
Custom RPC project - frequently asked questions and explanations (Registration Center)
The difference between abstract classes and interfaces
MySQL中count(*)的实现方式
Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis
MySQL limit x, -1 doesn't work, -1 does not work, and an error is reported
js判断对象是否是数组的几种方式
Mortal immortal cultivation pointer-2
Cloud native trend in 2022
List set map queue deque stack
Questions and answers of "signal and system" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
Aurora system model of learning database