[Qt-creator] Getting results from network in LocatorFilter

Mikhail Bryukhovets push.uni at gmail.com
Sun Mar 7 11:16:42 CET 2021


Hello!

I am trying to add suggestions functionality to my QtCerator plugin: When
user types search request in the locator there will be a displayed list of
suggested search queries based on entered text. Similar as it is done in
browsers or search engines. Suggestions are obtained from network as
results of GET requests to remote server. For example:
QNetworkRequest request;
request.setUrl(QUrl::fromUserInput("
https://example.com/user_input?action=suggest"));
auto reply = network_manager_.get(request);
QObject::connect(reply, &QNetworkReply::readyRead, [&](){
    qDebug() << "reply:" << reply->readAll();
});

So as I understand it I should make a network request inside matchesFor()
function of my class derived from Core::ILocatorFilter.
The first issue is: How and where do I obtain a result of a request to
return it to the user?
The second is: It seems that QNetworkAccessManager can't process
QNetworkRequest created in another thread (QObject: Cannot create children
for a parent that is in a different thread.
(Parent is QNetworkAccessManager(0x163c4d0), parent's thread is
QThread(0x6cc0d0), current thread is QThread(0x28b5810))
I didn't find similar cases in plugins provided with QtCreator so I hope
someone can point me in the right direction.

Mikhail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20210307/5c24a0e2/attachment.html>


More information about the Qt-creator mailing list