Skip to content
  • 0 Votes
    5 Posts
    552 Views
    SGaistS

    AFAIK, if this does happen you likely have other bigger issues. The signal is not related to the success of the request.

  • 0 Votes
    9 Posts
    706 Views
    P

    @JonB it works bro thank you
    problem fixed
    when i tried this before it doesn't open the window at all ... just flashing but now i understand why it's working
    Thank you <3

  • 0 Votes
    2 Posts
    966 Views
    VRoninV

    @LRDPRDX said in In what thread would a QObject be deleted if it was moved to another QThread?:

    the dtor must be called and executed in the secondary thread not the main one. Am I right?

    Correct, that's what connect(thread, &QThread::finished, worker, &QObject::deleteLater); does and as you noted>

    No more events will be processed in the thread, except for deferred deletion events.

    Do the deleteLater will still picked up after the finished is emitted and the destructor will run in the secondary thread

  • 0 Votes
    21 Posts
    3k Views
    H

    @LRDPRDX

    In terminal, "double free or corruption (out)" message is printed after the destructor has been called.

    Update: Sorry for bothering you. I was having similar issue. I saw your post in stackoverflow and then my problem solved when I allocated my QMainWindow object in heap instead of the stack.

    Many thanks!

  • 0 Votes
    5 Posts
    811 Views
    JonBJ

    @Yash001
    When items are removed from a model the view will update to reflect the new state. Widgets you have added via setIndexWidget() which are no longer present will be deleted by Qt infrastructure without you needing to delete them or disconnect from signals.

  • 0 Votes
    9 Posts
    2k Views
    M

    You need to add extra logic in your prog.

    Your problem seems very similar to the Copy/Cut/Paste logic. You don't know if the paste command is valid because you don't know if the user press copy command before that.
    Well, is up to you to register the states of this commands.

    So you need to implement the logic suitable to your case, for example, if the list of items is empty, obviously you cannot edit it, etc.

    About the interfaces (as others said), create them on the fly could be tricky and error prone. You can do it if only minor changes are to be made (hide/disable a few button/options)
    If the interfaces are very different, better way to create a unique persistent widget for each, and put them in a StackedWidget.

    Good luck :;)

  • 0 Votes
    6 Posts
    2k Views
    Christian EhrlicherC

    You should really read the chapter about the parent/child relationship here: https://doc.qt.io/qt-5/qobject.html#details

    ".... The parent takes ownership of the object; i.e., it will automatically delete its children in its destructor"

    So if they are all children of your mWidget then they will get deleted when mWidget is destroyed.

  • 0 Votes
    2 Posts
    768 Views
    S

    Had the same problem.

    Fixed it by not binding the object referenced by the role to a property and using the property but using the role name directly to acces the model item.

    Instead of

    property MyItem myItem: model.object text: myItem.foo

    try

    text: model.object.foo
  • 0 Votes
    5 Posts
    3k Views
    Y

    @mpergand Thank you for help.

  • 0 Votes
    3 Posts
    581 Views
    Y

    @koahnig thank you.

  • 0 Votes
    10 Posts
    4k Views
    IMAN4KI

    At long last! i decided to simply process reply in worker thread(Thanks @raven-worx ):

    using Header = QMap<QString, QString>; class HttpWorker : public QObject { Q_OBJECT public: struct HttpData { bool hasError = false; NetworkError error = NetworkError::NoError; QString errorString; QByteArray data; }; HttpWorker(QThread*, const QUrl&, const QUrlQuery&); ~HttpWorker(); void addHeaders(const Header&); enum Method { Post, Get }; void setMethod(Method m) { http_method = m; } Method method() const { return http_method; } private Q_SLOTS: void sendRequest(); private: QNetworkAccessManager manager; Header headers; QUrlQuery params; QUrl url; Method http_method = Post; private: void check(QNetworkReply*); void appendHeaders(QNetworkRequest*); Q_SIGNALS: void finished(HttpData); }; HttpWorker::HttpWorker(QThread* thread, const QUrl& _url, const QUrlQuery& _params) :url{ _url }, params{ _params } { qRegisterMetaType<HttpData>("HttpData"); moveToThread(thread); manager.moveToThread(thread); QObject::connect(thread, &QThread::started, this, &HttpWorker::sendRequest); QObject::connect(this, &HttpWorker::finished, thread, &QThread::quit); QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater); QObject::connect(thread, &QThread::finished, this, &HttpWorker::deleteLater); QObject::connect(&manager, &QNetworkAccessManager::finished, this, &HttpWorker::check); } HttpWorker::~HttpWorker() { } void HttpWorker::addHeaders(const Header& _headers) { headers = std::move(_headers); } void HttpWorker::appendHeaders(QNetworkRequest* req) { if (!req) return; QMapIterator<QString, QString> iterator(headers); while (iterator.hasNext()) { iterator.next(); req->setRawHeader(QByteArray::fromStdString(iterator.key().toStdString()), QByteArray::fromStdString(iterator.value().toStdString())); } } void HttpWorker::sendRequest() { const auto content_h = QStringLiteral("application/x-www-form-urlencoded"); if (method() == Post) { QNetworkRequest req(url); req.setHeader(QNetworkRequest::ContentTypeHeader, content_h); if (!headers.isEmpty()) appendHeaders(&req); const auto data = params.isEmpty() ? url.toEncoded() : params.toString(QUrl::FullyEncoded).toUtf8(); manager.post(req, data); } else { url.setQuery(params); QNetworkRequest req(url); req.setHeader(QNetworkRequest::ContentTypeHeader, content_h); manager.get(req); } } void HttpWorker::check(QNetworkReply* reply) { HttpData data; if (reply->error()) { data.hasError = true; data.error = reply->error(); data.errorString = reply->errorString(); } else { data.data = std::move(reply->readAll()); } emit finished(std::move(data)); reply->deleteLater(); }
  • 0 Votes
    6 Posts
    6k Views
    enjoysmathE

    @JEllery

    Thanks so much for solving this. It seems to solve my deletion-crash issue as well. :)