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

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

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

1、mainwindows.cpp

  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent) :
  5. QMainWindow(parent),
  6. ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. }
  10.  
  11. MainWindow::~MainWindow()
  12. {
  13. delete ui;
  14. }
  15.  
  16. #include <QDebug>
  17. #include "TClassFuncPtr.h"
  18.  
  19. void MainWindow::on_pbtnTest01_clicked()
  20. {
  21. //*
  22. CTest test;
  23.  
  24. void *pFunc = pointer_cast<void*>(&CTest::GetString);
  25.  
  26. Tcfp_Qs_II cfp;
  27. cfp.Set(&test, pFunc);
  28. QString str = cfp.Call(, );
  29. qDebug() << str;
  30. //*/
  31. /*
  32. CTest test;
  33. QString str = test.GetString(1, 3);
  34. //*/
  35. }
  36.  
  37. void MainWindow::on_pbtnTest02_clicked()
  38. {
  39. QString str = "";
  40. //*
  41. CTest test;
  42.  
  43. void *pFunc = pointer_cast<void*>(&CTest::GetIntFromString);
  44.  
  45. Tcfp_I_CQs cfp;
  46. cfp.Set(&test, pFunc);
  47. int iRtn = cfp.Call(str);
  48. qDebug() << str;
  49. //*/
  50. /*
  51. CTest test;
  52. int iRtn = test.GetIntFromString(str);
  53. qDebug() << iRtn;
  54. //*/
  55. }
  56.  
  57. void MainWindow::on_pbtnTest03_clicked()
  58. {
  59. QString str = "";
  60. //*
  61. CTest test;
  62.  
  63. void *pFunc = pointer_cast<void*>(&CTest::GetIntFromString01);
  64.  
  65. Tcfp_I_Qs cfp;
  66. cfp.Set(&test, pFunc);
  67. int iRtn = cfp.Call(str);
  68. qDebug() << iRtn;
  69. }
  70.  
  71. void MainWindow::on_pbtnTest04_clicked()
  72. {
  73. QString str = "";
  74. //*
  75. CTest test;
  76.  
  77. void *pFunc = pointer_cast<void*>(&CTest::GetIntFromString02);
  78.  
  79. Tcfp_I_Qsp cfp;
  80. cfp.Set(&test, pFunc);
  81. int iRtn = cfp.Call(&str);
  82. qDebug() << iRtn;
  83. }

2、TClassFuncPtr.h

  1. #ifndef TCLASSFUNCPTR_H
  2. #define TCLASSFUNCPTR_H
  3.  
  4. #include <QString>
  5.  
  6. // ZC: 子类 命名规则:“Tcfp_返回值类型_各个传入参数类型()”
  7.  
  8. class TClassFuncPtr
  9. {
  10. public:
  11. TClassFuncPtr()
  12. {
  13. FpObj = NULL;
  14. FpFunc = NULL;
  15. }
  16.  
  17. protected:
  18. void* FpObj; // ZC: 对象指针
  19. void* FpFunc; // ZC: 类函数的 函数地址(统一使用stdcall调用约定,函数传参/调用的时候 方便一点)
  20.  
  21. public:
  22. void Set(void *_pObj, void *_pFunc)
  23. {
  24. FpObj = _pObj;
  25. FpFunc = _pFunc;
  26. }
  27.  
  28. bool IsValid()
  29. {
  30. return ( (FpObj != NULL) && (FpFunc != NULL) );
  31. }
  32. };
  33.  
  34. class Tcfp_Qs_II :public TClassFuncPtr
  35. {
  36. public:
  37. QString __stdcall Call(int _i, int _j);
  38. };
  39.  
  40. class Tcfp_I_CQs :public TClassFuncPtr
  41. {
  42. public:
  43. int __stdcall Call(const QString _str);
  44. };
  45.  
  46. class Tcfp_I_Qs :public TClassFuncPtr
  47. {
  48. public:
  49. int __stdcall Call(QString &_str);
  50. };
  51.  
  52. class Tcfp_I_Qsp :public TClassFuncPtr
  53. {
  54. public:
  55. int __stdcall Call(QString *_pstr);
  56. };
  57.  
  58. // ZC: 获取 类函数指针(地址)
  59. template<typename dst_type,typename src_type>
  60. dst_type pointer_cast(src_type src)
  61. {
  62. return *static_cast<dst_type*>(static_cast<void*>(&src));
  63. }
  64. #endif // TCLASSFUNCPTR_H
  65.  
  66. class CTest
  67. {
  68. private:
  69. int Fi;
  70. public:
  71. QString __stdcall GetString(int _i, int _j);
  72.  
  73. int __stdcall GetIntFromString(const QString _str);
  74. int __stdcall GetIntFromString01(QString &_str);
  75. int __stdcall GetIntFromString02(QString *_pstr);
  76. };

3、TClassFuncPtr.cpp

  1. #include "TClassFuncPtr.h"
  2.  
  3. #pragma optimize( "", off )
  4. QString __stdcall Tcfp_Qs_II::Call(int _i, int _j)
  5. {
  6. if (IsValid())
  7. {
  8. _asm
  9. {
  10. push _j
  11. push _i
  12. mov eax,dword ptr [ebp+0xC]
  13. push eax
  14. mov eax,[this] // ZC: 貌似和语句“mov eax,this”是一样的效果...
  15. // [eax] ==> FpObj
  16. // [eax+4] ==> FpFunc
  17. push [eax]
  18. call [eax+]
  19. }
  20. }
  21. }
  22.  
  23. int __stdcall Tcfp_I_CQs::Call(const QString _str)
  24. {
  25. if (IsValid())
  26. {
  27. void *p = (void*)&_str;
  28. _asm
  29. {
  30. push p
  31. mov eax,[this] // ZC: 貌似和语句“mov eax,this”是一样的效果...
  32. // [eax] ==> FpObj
  33. // [eax+4] ==> FpFunc
  34. push [eax]
  35. call [eax+]
  36. }
  37. }
  38. }
  39.  
  40. int __stdcall Tcfp_I_Qs::Call(QString &_str)
  41. {
  42. if (IsValid())
  43. {
  44. _asm
  45. {
  46. mov eax,[ebp+0xC]
  47. push eax
  48. mov eax,[this] // ZC: 貌似和语句“mov eax,this”是一样的效果...
  49. // [eax] ==> FpObj
  50. // [eax+4] ==> FpFunc
  51. push [eax]
  52. call [eax+]
  53. }
  54. }
  55. }
  56.  
  57. int __stdcall Tcfp_I_Qsp::Call(QString *_pstr)
  58. {
  59. if (IsValid())
  60. {
  61. _asm
  62. {
  63. mov eax,[ebp+0xC]
  64. push eax
  65. mov eax,[this] // ZC: 貌似和语句“mov eax,this”是一样的效果...
  66. // [eax] ==> FpObj
  67. // [eax+4] ==> FpFunc
  68. push [eax]
  69. call [eax+]
  70. }
  71. }
  72. }
  73.  
  74. //#pragma optimize( "", on )
  75.  
  76. //#pragma optimize( "", off )
  77. QString __stdcall CTest::GetString(int _i, int _j)
  78. {
  79. __asm
  80. {
  81. mov eax,eax
  82. mov eax,eax
  83. mov eax,eax
  84. }
  85. Fi = ;
  86. return ( QString::number(_i)+","+QString::number(_j)+","+QString::number(Fi) );
  87. }
  88.  
  89. int __stdcall CTest::GetIntFromString(const QString _str)
  90. {
  91. return _str.toInt();
  92. }
  93.  
  94. int __stdcall CTest::GetIntFromString01(QString &_str)
  95. {
  96. return _str.toInt();
  97. }
  98.  
  99. int __stdcall CTest::GetIntFromString02(QString *_pstr)
  100. {
  101. return (*_pstr).toInt();
  102. }
  103.  
  104. #pragma optimize( "", on )

4、mainwindow.ui

  4.1、

  4.2、

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3. <class>MainWindow</class>
  4. <widget class="QMainWindow" name="MainWindow">
  5. <property name="geometry">
  6. <rect>
  7. <x>0</x>
  8. <y>0</y>
  9. <width>400</width>
  10. <height>300</height>
  11. </rect>
  12. </property>
  13. <property name="windowTitle">
  14. <string>MainWindow</string>
  15. </property>
  16. <widget class="QWidget" name="centralWidget">
  17. <widget class="QPushButton" name="pbtnTest01">
  18. <property name="geometry">
  19. <rect>
  20. <x>50</x>
  21. <y>40</y>
  22. <width>75</width>
  23. <height>23</height>
  24. </rect>
  25. </property>
  26. <property name="text">
  27. <string>Test01</string>
  28. </property>
  29. </widget>
  30. <widget class="QPushButton" name="pbtnTest02">
  31. <property name="geometry">
  32. <rect>
  33. <x>50</x>
  34. <y>70</y>
  35. <width>75</width>
  36. <height>23</height>
  37. </rect>
  38. </property>
  39. <property name="text">
  40. <string>Test02</string>
  41. </property>
  42. </widget>
  43. <widget class="QPushButton" name="pbtnTest03">
  44. <property name="geometry">
  45. <rect>
  46. <x>50</x>
  47. <y>100</y>
  48. <width>75</width>
  49. <height>23</height>
  50. </rect>
  51. </property>
  52. <property name="text">
  53. <string>Test03</string>
  54. </property>
  55. </widget>
  56. <widget class="QPushButton" name="pbtnTest04">
  57. <property name="geometry">
  58. <rect>
  59. <x>50</x>
  60. <y>130</y>
  61. <width>75</width>
  62. <height>23</height>
  63. </rect>
  64. </property>
  65. <property name="text">
  66. <string>Test04</string>
  67. </property>
  68. </widget>
  69. </widget>
  70. <widget class="QMenuBar" name="menuBar">
  71. <property name="geometry">
  72. <rect>
  73. <x>0</x>
  74. <y>0</y>
  75. <width>400</width>
  76. <height>17</height>
  77. </rect>
  78. </property>
  79. </widget>
  80. <widget class="QToolBar" name="mainToolBar">
  81. <attribute name="toolBarArea">
  82. <enum>TopToolBarArea</enum>
  83. </attribute>
  84. <attribute name="toolBarBreak">
  85. <bool>false</bool>
  86. </attribute>
  87. </widget>
  88. <widget class="QStatusBar" name="statusBar"/>
  89. </widget>
  90. <layoutdefault spacing="6" margin="11"/>
  91. <resources/>
  92. <connections/>
  93. </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. vs2010用NuGet(程序包管理)安装EF失败之解决办法

    今天用程序包管理控制台安装EF.报错.如下

  2. 将Mongo装为Windows的服务

    PHP的mongo扩展: 首先 下载一个PHP的mongo扩展, 地址:http://download.csdn.net/detail/qq_36387589/9819259 然后修改php.ini. ...

  3. mongodb权限

    1.在无密码模式下添加账号 db.createUser( { user: "user", pwd: "pwd", roles: [ { role: " ...

  4. redis windows版本下载

    https://github.com/dmajkic/redis/downloads http://windows.php.net/downloads/pecl/snaps/redis/3.1.4rc ...

  5. UVA 103

    /* 这题说的的是 N 维的坐标, 每个盒子的N维坐标 可以进行 随意方式的调换 然后求出 A全部的坐标小于B的 则 A 可以嵌套在B中 然后 计算出最多的 盒子嵌套个数 简单的状态转移 我为何如此的 ...

  6. OLAP引擎——Kylin介绍(很有用)

    转:http://blog.csdn.net/yu616568/article/details/48103415 Kylin是ebay开发的一套OLAP系统,与Mondrian不同的是,它是一个MOL ...

  7. java模拟表单上传文件,java通过模拟post方式提交表单实现图片上传功能实例

    java模拟表单上传文件,java通过模拟post方式提交表单实现图片上传功能实例HttpClient 测试类,提供get post方法实例 package com.zdz.httpclient; i ...

  8. SpringBoot——定时任务+WebSocket(问题)

    开发环境:win7 + idea2018 + jdk 1.8 + springboot 2.x 记一次出现问题,我在项目中先集成了websocket环境,并且测试通过,之后想要模拟实时推送的效果,虽然 ...

  9. P3313 [SDOI2014]旅行

    P3313 [SDOI2014]旅行 树链剖分+动态线段树(并不是lct) 显然的,我们对于每一个宗教都要维护一个线段树. (那么空间不是爆炸了吗) 在这里引入:动态开点线段树 就是需要的点开起来,不 ...

  10. MVC 扩展RadioButtonListFor和CheckBoxListFor

    学习MVC时候前端通常会用到HtmlHelper,使得前端编码简便很多.我们可能会经常用到htmlHelper中一些的EditorFor,LabelFor,ValiationMessageFor, 发 ...