How to query pointer variables in Qt?
In Qt, the typeid operator can be used to query the type of a pointer variable. Using the typeid operator requires including the header file
Here is an example code:
#include <iostream>
#include <typeinfo>
int main() {
int* ptr = nullptr;
// 查询指针变量的类型
std::cout << "Type of ptr: " << typeid(ptr).name() << std::endl;
return 0;
}
The output will be a string with type information, such as “Pi” indicating a pointer to an integer.
Please note that the typeid operator returns a type_info object, not a direct string of the type name. To retrieve the type name as a string, you can use the name() method of the type_info object.