首页 \ 问答 \ 使用QSortFilterProxyModel在QTreeView中自动选择文件(Auto selecting files in QTreeView with QSortFilterProxyModel)

使用QSortFilterProxyModel在QTreeView中自动选择文件(Auto selecting files in QTreeView with QSortFilterProxyModel)

我正在使用带有QFileSystemModelQSortFilterProxyModel QFileSystemModel 。 我的目标是使用treeviews keyboardSearch方法为用户预选某些文件。

QFileSystemModel提供信号directoryLoaded ,让我知道何时可以选择文件。 这本身可以正常工作,但与QSortFilterProxy结合使用失败。 在排序和keyBoardSearch失败之前,信号似乎被触发了。

有没有办法向QSortFilterProxy添加类似的信号? 或者另一种方式?


I'm using a QTreeView with QFileSystemModel and QSortFilterProxyModel. My goal is to pre-select certain files for the user using the treeviews keyboardSearch method.

QFileSystemModel offers the signal directoryLoaded to let me know when i can select the files. This works fine on its own but fails in combination with the QSortFilterProxy. The signal seems to be fired before the sorting and keyBoardSearch fails.

Is there a way to add a similar signal to QSortFilterProxy? Or maybe another way?


原文:https://stackoverflow.com/questions/34798054
更新时间:2023-05-21 22:05

最满意答案

仅当您尝试通过指针/引用访问对象时,才会应用严格别名。 您没有尝试通过void*访问该对象,因此严格别名规则甚至不适用(此处保护您的规则是static_cast上的规则,允许它将指向任何类型的指针转​​换为void*并返回,只要你把它投回去的类型就是它之前的类型)。

类似地,允许指向同一类型的指针。 所以tstatic_cast<T*>结果允许别名,因此两者都不违反严格的别名。


Strict aliasing only applies when you are attempting to access the object through a pointer/reference. You are not attempting to access the object through a void*, so the strict aliasing rule doesn't even apply (the rule that protects you here is the rule on static_cast that allows it to convert a pointer to any type to void* and back, so long as the type you cast it back to is exactly the type it was before).

Similarly, pointers to the same type are allowed to alias. So t and the result of static_cast<T*> are allowed to alias and thus having both do not violate strict aliasing.

相关问答

更多
  • 遇到严格混叠问题的典型情况是将结构体(如设备/网络msg)覆盖到系统字大小的缓冲区上(如指向uint32_t或uint16_t s的指针)。 当您将结构体覆盖到这样的缓冲区上,或者通过指针转换将缓冲区覆盖到这样的结构体上时,可以轻易地违反严格的别名规则。 所以在这种设置中,如果我想发送一个消息,我必须有两个不兼容的指针指向同一块内存。 我可能会天真地编写这样的东西: struct Msg { unsigned int a; unsigned int b; }; void SendWord( ...
  • 为了: 是。 GCC会假定指针不能别名。 例如,如果您通过一个分配,然后从另一个分配,GCC可以作为优化重新排序读取和写入 - 我已经看到这在生产代码中发生,调试不愉快。 一些。 您可以使用联合来表示您需要重新解释的内存。 你可以使用reinterpret_cast 。 你可以通过char *你重新解释内存的位置 - char *被定义为能够隐藏任何东西。 你可以使用一个类型__attribute__((__may_alias__)) 。 您可以使用-fno-strict-aliasing全局关闭别名假设。 ...
  • 您不能像以下那样通过不兼容的指针解释对象: *(uint32_t*) hash; 这样做会导致对齐,字节顺序和违反严格别名的问题,这会导致未定义的行为。 会发生什么,您将数组哈希的前四个字节解释为无符号32位整数。 uint32_t* p = ( uint32_t* )hash ; //cast must be there, pointer p is not valid uint32_t u = *p ; //dereference the pointer, this is undefined ...
  • 在大多数编译器中,它会按照您的期望执行, 直到优化程序决定使用死代码消除或将赋值移动到f 。 这使得基本上不可能测试任何给定的编译器是否总是按照您的预期执行 - 它可能适用于一个特定的程序,但稍微不同的可能会失败。 严格别名规则基本上只是告诉编译器实现者“你可以通过假设它们永远不会别名来相当自由地重新排列和消除这些东西”。 当执行会导致此代码失败的事情没有用时,优化器可能不会,因此您不会看到问题。 最重要的是,谈论“哪些编译器将会起作用”是没有用的 ,因为如果某些看似无关的内容发生变化,它们可能会在将来突然 ...
  • *((U*) &data)将违反严格别名,如果这是reinterpret_cast并且类型U不允许对类型T进行别名。 允许的类型显示在此列表中 。 该规则涉及阅读和写作 。 这是一篇很好的文章,解释了规则背后的一些基本原理。 如主严格别名线程所述,您可以使用memcpy作为解决方法,例如: U u; memcpy( &u, &data, sizeof u ); return u; 而在另一个功能 memcpy( &data, &in, sizeof data ); 请注意,类类型的原始字节副本受到一些限 ...
  • 仅当您尝试通过指针/引用访问对象时,才会应用严格别名。 您没有尝试通过void*访问该对象,因此严格别名规则甚至不适用(此处保护您的规则是static_cast上的规则,允许它将指向任何类型的指针转换为void*并返回,只要你把它投回去的类型就是它之前的类型)。 类似地,允许指向同一类型的指针。 所以t和static_cast结果允许别名,因此两者都不违反严格的别名。 Strict aliasing only applies when you are attempting to access the ...
  • 是的,它是无效的,但不是因为你正在将char*转换为A* :这是因为你没有获得实际指向A*的A*并且正如你所识别的那样,没有任何类型的别名选项适合。 你可能想要这样的东西: #include #include struct A { int t; }; char *buf = new char[sizeof(A)]; A* ptr = new (buf) A; ptr->t = 1; // Also valid, because points to an actu ...
  • 该标准包含此注释: [ 注意:典型的实现会将aligned_storage定义为: template struct aligned_storage { typedef struct { alignas(Alignment) unsigned char __data[Len]; } type; }; - 结束说明 ] - 指针修改[meta.trans.ptr] 20.9.7.5/1 align_storage ...
  • 当然,这违反了严格的别名。 代码通过不同类型的指针访问值,而不是char* 。 int main() { short tab[] = {1,2,3,4}; int* ps = (int*)(&tab[0]); *ps = 3; if(tab[0] == 1) return 1; return 0; } 允许代码在那里返回1。 因为写入* ps是对int的写入,并且根据严格的别名规则, int指针不可能指向short 。 因此,允许优化器看到tab数组未被修改,优化i ...
  • 严格的别名规则意味着您不应取消引用指向同一内存位置的不同类型的指针。 由于在您发布的代码中您永远不会取消引用,因此无法在不查看所有代码的情况下判断这是否违反规则。 此外,别名为char *类型是一个例外,并不违反规则。 这意味着您可以通过将其指针转换为char *并取消引用它来访问包含任何类型的内存位置。 总结: 如果buffer点在包含int的内存位置上,并且从int*转换为char* ,则这是有效的。 但是,您应该使用reinterpret_cast 如果缓冲区指向包含字符的内存位置,则取消引用int* ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)