草庐IT

Delegate

全部标签

c++ - QComboBox 不调用委托(delegate)方法

我想通过模型和委托(delegate)插入QWidgets(而不是字符串)来自定义QComboBox>:QComboBox*cb=newQComboBox(this);FeatureModel*featureModel=newFeatureModel(cb);cb->setModel(featureModel);ComboBoxItemDelegate*comboBoxItemDelegate=newComboBoxItemDelegate(cb);cb->setItemDelegate(comboBoxItemDelegate);FeatureModel继承自QAbstractLis

c++ - C++11 委托(delegate)构造函数功能的实现导致了几个警告

我已尝试实现C++11功能(我将此答案用作引用CanIcallaconstructorfromanotherconstructor(doconstructorchaining)inC++?)。显然,我做错了,但我不明白为什么。我在下面的代码中收到了几个警告:成员_output未在此构造函数中初始化成员_protocol_scanner未在此构造函数中初始化成员_state未在此构造函数中初始化成员_source未在此构造函数中初始化这是代码:classUartScanner{public:UartScanner(periph::IStreamDevice*source,periph::

c++ - GCC 无法优化涉及成员函数指针的委托(delegate) lambda 函数

我使用GCC4.9.2和clang3.6.0编译了以下c++14代码。我使用了-O3标志。#includestructS{inta;intA()const{returna;}};templateintFunc(F&&f,Args&&...args){returnf(std::forward(args)...);}usingPtrA=int(S::*)()const;intF(Sconst&s,PtrAptr){return(s.*ptr)()*5;}intp(Sconst&s){returns.A()*5;}intP1(Sconst&s){returnFunc(&F,s,&S::A);

c# - 我想从 C++ 非托管代码调用 C# 委托(delegate)。无参数委托(delegate)工作正常,但带参数的委托(delegate)使我的程序崩溃

以下是来自未管理的dll的函数代码。它接受一个函数指针作为参数,并简单地返回被调用函数返回的值。extern__declspec(dllexport)int_stdcallcallDelegate(int(*pt2Func)());extern__declspec(dllexport)int_stdcallcallDelegate(int(*pt2Func)()){intr=pt2Func();returnr;}在托管C#代码中,我使用委托(delegate)调用上面的umanged函数。unsafepublicdelegateintmydelegate();unsafepublici

c++ - 调用委托(delegate)构造函数时避免复制

具有委托(delegate)构造函数的类classA{A(SomeObjectobj,//requiresanewcopyoftheobjectintx,conststring&y){//additionallogic}A(SomeObjectobj,conststring&y):A(obj,0,y){}//willobjbecopied?};目标用途:SomeObjectobj;Aa1(obj,"first");Aa2(obj,"second");设计是在执行构造A时恰好构造一次SomeObject。传递obj是否会在委托(delegate)给另一个构造函数时导致另一个SomeObj

.net - 在非托管代码中处理托管委托(delegate)

我知道我可以使它在技术上起作用,但我想实现尽可能干净的解决方案。情况是这样的:我有一个托管库,它包装了一个非托管C风格的库。我目前包装的C风格库功能执行一些涉及字符串列表的处理。库的客户端代码可以提供一个委托(delegate),这样在列表处理过程中,如果遇到“无效”的情况,库可以通过这个委托(delegate)回调给客户端,让他们选择使用的策略(抛出异常,替换无效字符等)我最希望拥有的是将所有托管C++隔离在一个函数中,然后能够调用一个单独的函数,该函数仅采用非托管参数,以便所有nativeC++和非托管代码都在该处隔离一点。为这个非托管代码提供回调机制被证明是我的症结所在。#pra

c++ - 如何使用 Item Delegate 检测 QListView <-> QAbstractListModel 中的行选择?

我选择的QListView->QAbstractListModel似乎对内置选择支持为零。我必须从头开始编写所有内容吗?在UI中捕获选择事件,将模型项标记为已选中等?似乎没有开箱即用的支持。奇怪的是有一个QItemSelectionModel确实支持这个,但是你不能将它与QListView一起使用,因为它不是从QAbstract派生的......我的模型类是否应该使用多重继承来继承QItemSelectionModel和QAbstractListModel?否则我不知道如何才能避免自己重写这个功能。我的最终目标是让绘制我的项目的代理知道项目是否被选中,包括在paint和sizeHint

c# - 在 C# 委托(delegate)中编码 va_list

我正在尝试通过C#实现此功能:C头文件:typedefvoid(LogFunc)(constchar*format,va_listargs);boolInit(uint32version,LogFunc*log)C#实现:staticclassNativeMethods{[DllImport("My.dll",SetLastError=true)]internalstaticexternboolInit(uintversion,LogFunclog);[UnmanagedFunctionPointer(CallingConvention.Cdecl,SetLastError=true)

c++ - 使用 qt 自定义委托(delegate)正确突出显示

我正在制作一个表格控件,除了其模型的DisplayRole中的数据外,它还显示一些额外的文本数据。在所有其他方面,文本和单元格显示应该相同。我遇到的问题是正确显示突出显示的单元格。我目前正在使用以下代码:voidMatchDelegate::paint(QPainter*painter,constQStyleOptionViewItem&option,constQModelIndex&index)const{if(option.state&QStyle::State_Selected)painter->fillRect(option.rect,option.palette.highli

c++ - 每当使用 constexpr 指定调用的函数时,将委托(delegate)方法声明为 constexpr

请考虑以下类(class)templateclassfoo{public:autobar(){returnm_t.bar();}private:Tm_t;};如果我们想要foo::bar不抛出任何时候T::bar是非抛出的,我们可以将其声明更改为autobar()noexcept(noexcept(m_t.bar())){returnm_t.bar();}但如果我们想要,我们能做什么foo::bar用constexpr指定每当T::bar用constexpr指定?我们可以写吗constexprautobar()noexcept(noexcept(m_t.bar())){returnm_