我需要一个QCombox,根据文本输入过滤项目.如果我将QCombobox设置为可编辑,则用户可以插入文本并自动创建QCompleter.但是项目没有被过滤,我不希望用户添加新项目.
是否有可能将此功能添加到QCombobox?
对于不需要任何传递信息(对象实例或类)的方法,更好的方法是什么,因为例如它们只是进行简单的转换.@staticmethod还是方法?
class Foo(object):
def __init__(self, trees):
self.money = Foo.trees2money(trees)
@staticmethod
def trees2money(trees):
return trees * 1.337
class Quu(object):
def __init__(self, trees):
self.money = self.trees2money(trees)
def trees2money(self, trees):
return trees * 1.337
Run Code Online (Sandbox Code Playgroud) 我有一个vector<Person>想要将每个对象的属性名称提取到a vector<string>.for-each循环使它正常工作,但有没有更好的方法来使用类似的东西std::copy()并告诉他使用特定的方法(在这种情况下是name()getter)将值复制到我的vector<string>?
class Person {
int a;
string n;
public:
Person(int age, string name) : a(age), n(name) {}
int age() const { return a; }
string name() const { return n; }
};
vector<Person> ppl = { Person(12, "Tim"), Person(21, "Tom") };
vector<string> names;
// question
// copy(ppl.begin(), ppl.end(), ????.name());
for (Person& p : ppl)
names.push_back(p.name());
copy(names.begin(), names.end(), ostream_iterator<string>(cout, ", "));
Run Code Online (Sandbox Code Playgroud)