qt-opensource-windows-x86-msvc2010_opengl-5.3.2.exe

ZC: “const QString” 作传入参数的时候,不太会弄... 貌似 还是在进行构建等的操作,按照暂时的水平这种情况还不太会弄... 于是 用“QString&”或“QString*”作参数

ZC: Qt调试 比较麻烦,还是使用 VS2010 来调试 看汇编的...

1、mainwindows.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
} MainWindow::~MainWindow()
{
delete ui;
} #include <QDebug>
#include "TClassFuncPtr.h" void MainWindow::on_pbtnTest01_clicked()
{
//*
CTest test; void *pFunc = pointer_cast<void*>(&CTest::GetString); Tcfp_Qs_II cfp;
cfp.Set(&test, pFunc);
QString str = cfp.Call(, );
qDebug() << str;
//*/
/*
CTest test;
QString str = test.GetString(1, 3);
//*/
} void MainWindow::on_pbtnTest02_clicked()
{
QString str = "";
//*
CTest test; void *pFunc = pointer_cast<void*>(&CTest::GetIntFromString); Tcfp_I_CQs cfp;
cfp.Set(&test, pFunc);
int iRtn = cfp.Call(str);
qDebug() << str;
//*/
/*
CTest test;
int iRtn = test.GetIntFromString(str);
qDebug() << iRtn;
//*/
} void MainWindow::on_pbtnTest03_clicked()
{
QString str = "";
//*
CTest test; void *pFunc = pointer_cast<void*>(&CTest::GetIntFromString01); Tcfp_I_Qs cfp;
cfp.Set(&test, pFunc);
int iRtn = cfp.Call(str);
qDebug() << iRtn;
} void MainWindow::on_pbtnTest04_clicked()
{
QString str = "";
//*
CTest test; void *pFunc = pointer_cast<void*>(&CTest::GetIntFromString02); Tcfp_I_Qsp cfp;
cfp.Set(&test, pFunc);
int iRtn = cfp.Call(&str);
qDebug() << iRtn;
}

2、TClassFuncPtr.h

#ifndef TCLASSFUNCPTR_H
#define TCLASSFUNCPTR_H #include <QString> // ZC: 子类 命名规则:“Tcfp_返回值类型_各个传入参数类型()” class TClassFuncPtr
{
public:
TClassFuncPtr()
{
FpObj = NULL;
FpFunc = NULL;
} protected:
void* FpObj; // ZC: 对象指针
void* FpFunc; // ZC: 类函数的 函数地址(统一使用stdcall调用约定,函数传参/调用的时候 方便一点) public:
void Set(void *_pObj, void *_pFunc)
{
FpObj = _pObj;
FpFunc = _pFunc;
} bool IsValid()
{
return ( (FpObj != NULL) && (FpFunc != NULL) );
}
}; class Tcfp_Qs_II :public TClassFuncPtr
{
public:
QString __stdcall Call(int _i, int _j);
}; class Tcfp_I_CQs :public TClassFuncPtr
{
public:
int __stdcall Call(const QString _str);
}; class Tcfp_I_Qs :public TClassFuncPtr
{
public:
int __stdcall Call(QString &_str);
}; class Tcfp_I_Qsp :public TClassFuncPtr
{
public:
int __stdcall Call(QString *_pstr);
}; // ZC: 获取 类函数指针(地址)
template<typename dst_type,typename src_type>
dst_type pointer_cast(src_type src)
{
return *static_cast<dst_type*>(static_cast<void*>(&src));
}
#endif // TCLASSFUNCPTR_H class CTest
{
private:
int Fi;
public:
QString __stdcall GetString(int _i, int _j); int __stdcall GetIntFromString(const QString _str);
int __stdcall GetIntFromString01(QString &_str);
int __stdcall GetIntFromString02(QString *_pstr);
};

3、TClassFuncPtr.cpp

#include "TClassFuncPtr.h"

#pragma optimize( "", off )
QString __stdcall Tcfp_Qs_II::Call(int _i, int _j)
{
if (IsValid())
{
_asm
{
push _j
push _i
mov eax,dword ptr [ebp+0xC]
push eax
mov eax,[this] // ZC: 貌似和语句“mov eax,this”是一样的效果...
// [eax] ==> FpObj
// [eax+4] ==> FpFunc
push [eax]
call [eax+]
}
}
} int __stdcall Tcfp_I_CQs::Call(const QString _str)
{
if (IsValid())
{
void *p = (void*)&_str;
_asm
{
push p
mov eax,[this] // ZC: 貌似和语句“mov eax,this”是一样的效果...
// [eax] ==> FpObj
// [eax+4] ==> FpFunc
push [eax]
call [eax+]
}
}
} int __stdcall Tcfp_I_Qs::Call(QString &_str)
{
if (IsValid())
{
_asm
{
mov eax,[ebp+0xC]
push eax
mov eax,[this] // ZC: 貌似和语句“mov eax,this”是一样的效果...
// [eax] ==> FpObj
// [eax+4] ==> FpFunc
push [eax]
call [eax+]
}
}
} int __stdcall Tcfp_I_Qsp::Call(QString *_pstr)
{
if (IsValid())
{
_asm
{
mov eax,[ebp+0xC]
push eax
mov eax,[this] // ZC: 貌似和语句“mov eax,this”是一样的效果...
// [eax] ==> FpObj
// [eax+4] ==> FpFunc
push [eax]
call [eax+]
}
}
} //#pragma optimize( "", on ) //#pragma optimize( "", off )
QString __stdcall CTest::GetString(int _i, int _j)
{
__asm
{
mov eax,eax
mov eax,eax
mov eax,eax
}
Fi = ;
return ( QString::number(_i)+","+QString::number(_j)+","+QString::number(Fi) );
} int __stdcall CTest::GetIntFromString(const QString _str)
{
return _str.toInt();
} int __stdcall CTest::GetIntFromString01(QString &_str)
{
return _str.toInt();
} int __stdcall CTest::GetIntFromString02(QString *_pstr)
{
return (*_pstr).toInt();
} #pragma optimize( "", on )

4、mainwindow.ui

  4.1、

  4.2、

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pbtnTest01">
<property name="geometry">
<rect>
<x>50</x>
<y>40</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Test01</string>
</property>
</widget>
<widget class="QPushButton" name="pbtnTest02">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Test02</string>
</property>
</widget>
<widget class="QPushButton" name="pbtnTest03">
<property name="geometry">
<rect>
<x>50</x>
<y>100</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Test03</string>
</property>
</widget>
<widget class="QPushButton" name="pbtnTest04">
<property name="geometry">
<rect>
<x>50</x>
<y>130</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Test04</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>17</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

5、

ZC_C++类函数指针_模拟_Delphi类函数指针_Qt例子的更多相关文章

  1. ZC_C++类函数指针_模拟_Delphi类函数指针

    ZC: C++的类函数指针 不像 Delphi的类函数指针,前者 需要规定死 是哪个类的函数的指针,后者就不需要 很灵活. 测试环境: Win7x64 cn_visual_studio_2010_ul ...

  2. C++第四篇--重载_指针_引用

    C++第四篇--重载_指针_引用 1. 基础知识 重载:函数名相同,根据参数不同(类型.数量.顺序不同)调用同名函数 指针和引用:引用就是别名,引用时必须初始化,引用你定义的变量. int a; in ...

  3. ca71a_c++_指向函数的指针_通过指针调用函数txwtech

    /*ca71a_c++_指向函数的指针_通过指针调用函数用typedef简化函数指针的定义简化前: bool(*pf)(const string&, const string &); ...

  4. c语言中较常见的由内存分配引起的错误_内存越界_内存未初始化_内存太小_结构体隐含指针

    1.指针没有指向一块合法的内存 定义了指针变量,但是没有为指针分配内存,即指针没有指向一块合法的内浅显的例子就不举了,这里举几个比较隐蔽的例子. 1.1结构体成员指针未初始化 struct stude ...

  5. C语言_初步了解一下指针

    指针的基本概念 在计算机中,所有的数据都是存放在存储器中的. 一般把存储器中的一个字节称为一个内存单元, 不同的数据类型所占用的内存单元数不等,如整型量占2个单元,字符量占1个单元等.为了正确地访问这 ...

  6. 零基础逆向工程24_C++_01_类_this指针_继承本质_多层继承

    1 类内的成员函数和普通函数的对比 1.1 主要是从参数传递.压栈顺序.堆栈平衡来总结. 1.参数传递:成员函数多传一个this指针 2.压栈顺序:成员函数会将this指针压栈,在函数调用取出 3.堆 ...

  7. 【c实现,vc6调试通过】给出一字符串指针,计算出字符串指针中单词数

    #include <stdio.h> /* 给出一字符串指针,计算出字符串指针中单词数, 单词不包括'.',',',';','?','_','"',由0-9数字或26个字母组成 ...

  8. Qt 智能指针学习(7种指针)

    Qt 智能指针学习 转载自:http://blog.csdn.net/dbzhang800/article/details/6403285 从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ ...

  9. 不可或缺 Windows Native (18) - C++: this 指针, 对象数组, 对象和指针, const 对象, const 指针和指向 const 对象的指针, const 对象的引用

    [源码下载] 不可或缺 Windows Native (18) - C++: this 指针, 对象数组, 对象和指针, const 对象,  const 指针和指向 const 对象的指针, con ...

随机推荐

  1. isKindOfClass isMemeberOfClass 的区分

    isKindOfClass If you use such constructs in your code, you might think it is alright to modify an ob ...

  2. CentOS6.5安装Twemproxy集群

    Twemproxy,也叫Nutcraker.是一个Twtter开源的一个Redis和Memcache代理服务器. Redis作为一个高效的缓存服务器,非常具有应用价值.但是当使用比较多的时候,就希望可 ...

  3. PIMPL(二)

    文档下载 上一篇文档,PIMPL(一) 1 如何使用PIMPL 有多种方式实现PIMPL,这里按照<Effective C++>中介绍的方式. 1.1 基本步骤 假设原有Person如下: ...

  4. time使用方法

  5. linux两种类型服务管理

    linux服务分成两个大类 一.rpm包安装  ---------独立的服务  和  基于xinetd服务 二.源代码安装 rpm包安装的服务,查看命令是 chkconfig --list rpm安装 ...

  6. ServiceStack DotNet Core前期准备

    下载DotNet Core SDK 下载地址:https://dotnet.microsoft.com/download. 安装完成之后通过cmd的命令行进行确认. 官方自带的cmd比较简陋,可以用c ...

  7. JProfiler8 远程监控tomcat配置过程

    1. 阅读人群 1.熟悉liunx服务器,起码知道liunx常见的命令 2.熟悉tomcat容器,起码知道怎么tomcat的启动以及停止 3.熟悉java编程语言,JProfiler8是专门监控jav ...

  8. htm5之视频音频(shit IE10都不支持)

    <p style="color: red; background-color: black;"> 视频<br /> autoplay autoplay 如果 ...

  9. # 20145106 《Java程序设计》第6周学习总结

    教材学习内容总结 来源和目的都不知道的情况下还是可以撰写程序的,有这类需求的时候,可以设计一个通用的dump()方法.dump方法接受inputstream与outputstream实例,分别代表读取 ...

  10. tomcat部署项目如何去掉项目名称

    去掉项目名和端口: 首先,进入tomcat的安装目录下的conf目录,我的目录是 /usr/local/apache-tomcat-6.0.20/conf,编辑文件server.xml. 1.去除端口 ...