我有一个简单的应用程序,只有一个QPlainTextEdit,基本上和Qt的例子一样:
http://qt-project.org/doc/qt-5.1/qtwidgets/mainwindows-application.html
当我按下Ctrl + Z时,它会调用undo.当我按Ctrl + A时,它会选择所有文本.还行吧.
但是当我按下Ctrl + E或Ctrl + R(菜单中未定义)时,字符"e"和"r"将出现在QSimpleTextEdit中.
我该如何防止这种情况?如何"过滤"已定义为菜单快捷键并使其保持工作的按键,并"防止"未定义为菜单快捷键的那些按键出现在编辑中?
当我跑:
exec "print __name__"
Run Code Online (Sandbox Code Playgroud)
它打印__main__.
但是当我跑步时:
exec "print __name__" in {}
Run Code Online (Sandbox Code Playgroud)
它打印__builtin__.
如何使第二个例子也打印__main__?
我试图实现的是运行一段代码,exec以便从它的角度看它是从命令行运行的.
我想用干净的范围来修改代码,但第二个例子打破了依赖的代码if __name__ == "__main__".如何解决这个问题?
我有很多像这样的代码:
otherString1 = myString1.replace("a", "b").replace("c", "d").replace("e", "f");
otherString2 = myString2.replace("a", "b").replace("c", "d").replace("e", "f");
otherString3 = myString3.replace("a", "b").replace("c", "d").replace("e", "f");
Run Code Online (Sandbox Code Playgroud)
我想不要replace一次又一次地重复这些方法.重新分解此类代码的正确方法是什么?我是C++的新手......
我以为我能做到:
#define REPLACE .replace("a", "b").replace("c", "d").replace("e", "f")
otherString1 = myString1#REPLACE;
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
我显然不能修补字符串类来添加myReplace()...
该怎么办?我应该将替换代码放入标题或sourse文件中吗?怎么样的static,inline,const东西呢?我应该创建一个完整的帮助器类和一个帮助器方法,还是应该在某个地方创建一个函数?怎么样的:
[helper.hpp]
static inline const myReplace(const StringClass s);
[helper.cpp]
static inline const myReplace(const StringClass s) {
return s.replace("a", "b").replace("c", "d").replace("e", "f");
}
[somefile.cpp]
include "helper.hpp"
otherString3 = myReplace(myString3);
Run Code Online (Sandbox Code Playgroud)