我觉得有人必须尝试这个,但如果一个观察者需要很长时间,我无法想出一个很好的方法来做某事.
这是我想要的流程.
Start a search.
If the search takes longer than some time,
show a spinner or show progress bar.
When finished do subscription action and hide spinner/progress bar.
Run Code Online (Sandbox Code Playgroud)
我能想到的最接近的就像一个Zip
manager.search(searchTerm)
.zip(Observable.Timer(1, TimeUnit.SECONDS))
.subscribe(
// if the search is non null then we are good
// if the long time is non 0 we need to show spinner
);
Run Code Online (Sandbox Code Playgroud)
还有更好的事吗?我整天都在努力,没有成功.在一个完美的世界里,我觉得我会想要这样的东西
manager.search(searchTerm)
.timeout(i -> /* do timeout stuff */, 1, TimeUnit.SECONDS)
.subscribe(item -> /* do search result stuff */);
Run Code Online (Sandbox Code Playgroud) 我有火并且忘记了不需要很长时间的操作,但是我想要在后台反复运行它们.生命周期基本上是与服务器的连接存在或已经过了10秒.我不知道如何存储这些,以便我可以有效地清理它们,同时仍然保持正确的生命周期.
Subscription fireAndForget = service.doSomething()
.timeout(10, TimeUnit.SECONDS)
.subscribe( () -> {
otherService.doAction()
}, (e) -> { Log.e("error", e) });
// what do I do with fireAndForget???
// If I use a CompositeSubscription
subscriptions.add(fireAndForget) // how does it get removed????
Run Code Online (Sandbox Code Playgroud)
我可以在我的连接上有一个CompositeSubscription,它可以保留它们,但是当操作完成后如何清除它们呢?在订阅取消订阅时,我是否应该打扰清除CompositeSubscription?我对Rx比较陌生,所以我不确定我是不是只是想做一些Rx不打算做的事情.
我在我的应用程序中使用的库,iris xmpp库中有信号.在Mac OS X和Linux上一切正常,但Windows产生了大量未找到警告的信号.
warning: QObject::connect: signal not found in XMPP::AdvancedConnector
warning: QObject::connect: signal not found in XMPP::AdvancedConnector
warning: QObject::connect: signal not found in XMPP::AdvancedConnector
warning: QObject::connect: signal not found in XMPP::AdvancedConnector
warning: QObject::connect: signal not found in XMPP::QCATLSHandler
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in XMPP::ClientStream
warning: QObject::connect: signal not found in …Run Code Online (Sandbox Code Playgroud) 字符串temp等于我的调试器中的"ZERO:\ t.WORD\t1".(我文件的第一行)
string temp = RemoveWhiteSpace(data);
int i = 0;
if ( temp.length() > 0 && isalpha(temp[0]) )
cout << "without true worked" << endl;
if ( temp.length() > 0 && isalpha(temp[0]) == true )
cout << "with true worked" << endl;
Run Code Online (Sandbox Code Playgroud)
这是我的代码,用于检查temp的第一个字符是否为az,AZ.第一个if语句将评估为true,第二个将评估为false.为什么?!?!?!即使没有"temp.length()> 0 &&",我也试过这个,但它仍然评估为false.它只是讨厌"== true".我唯一能想到的是isalpha()返回!= 0和true == 1.然后,你可以得到isalpha()== 2!= 1.但是,我不知道C++是不是......奇怪的.
顺便说一句,我不需要知道"== true"在逻辑上毫无意义.我知道.
输出是
without true worked
Run Code Online (Sandbox Code Playgroud)
在Ubuntu 9.10上使用GNU GCC编译CodeBlock(如果这很重要)
所以我有这个函数来添加监听器,它转换一个类的共享指针,以便我可以在收到通知后稍后调用它.
void registerListener(std::shared_ptr<T> listener)
{
if (!listener) {
qCWarning(OBSERVER_LOGGER) << "Attempted to register a null observer.";
return;
}
// TODO make a foreach function that removes dead listeners to get rid of this code dupe
for (auto iter=listeners.begin(); iter != listeners.end(); ) {
if (auto shared = iter->lock()) {
if (listener == shared) {
return;
}
iter++;
} else {
iter = listeners.erase(iter);
}
}
auto weak = std::weak_ptr<T>(listener);
listeners.push_back(weak);
}
void notify(std::function<void(std::shared_ptr<T>)> onNotify)
{
// TODO make a foreach …Run Code Online (Sandbox Code Playgroud) 我想制作一个看起来像这样的视图(为简洁起见,我在此不再赘述)
__________
| text |
|__________|
| |headr|
|____|_____|
|text|item1|
| |item2|
| | |
|text|item3|
| |item4|
| |item5|
| |item6|
|____|_____|
Run Code Online (Sandbox Code Playgroud)
并一直尝试使用GridLayout做到这一点。问题是我可能有很多行。这仅取决于我的模型。因此,我希望能够有一个重复相同n个元素的转发器。但是,它似乎只包含一个组成部分。我想重复一个元素,但这不是GridLayout找出间距的方式。因此,除了使用动态对象创建外,这似乎是不可能的。
我试图重复的实际项目的代码是这样的
Text {
Layout.alignment: Qt.AlignHCenter
text: abbr
color: "#545454"
}
VerticalRule {
Layout.fillHeight: true
}
ColumnLayout {
Repeater {
model: getModel()
Image {}
}
}
VerticalRule {
Layout.fillHeight: true
}
ColumnLayout {
Repeater {
model: getModel()
Image {}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,有什么方法可以轻松地在qml中做到这一点,或者当我涉及这种超级特定的表格格式时,我是自己一种。
我知道之前已经提出过一个非常相似的问题,"在c ++头文件中使用命名空间",但我的内部是命名空间.
namespace foo {
using namespace std; // what does this do?
class Bar { ... }
}
Run Code Online (Sandbox Code Playgroud)
这是否与其他问题完全相同,只是在所有地方使用声明?它只在该命名空间中执行吗?它只在标题中执行吗?