Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Modal loop issues inside Button "clicked"

Modal loop issues inside Button "clicked"

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 641 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QbProg
    wrote on last edited by
    #1

    Hello,
    I'm using Qt quick controls to adapt an existing application. In a Button handler, I call a C++ function that enters a modal loop (tryed both a while(true) QApplication::processMessage or a new QEventLoop ).

    Once entered the loop, the button start misbehaving, i.e. everytime I click in any point of the screen (possibly another mouseArea), the click is still captured by the button (which may also be inactive) and more and more clicked events get generated improperly. It seems that the button keeps the mouse captured until you exit the clicked handler.
    Any hint about this? Should I file a bug?

    I know that probably modal loops are not a good practice, but I need to adapt an existing application and fake some modal interfaces using qt quick (messageboxes, small dialogs,etc...) and I don't want to change all the application flow.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      israelins85
      wrote on last edited by
      #2

      Hello, this bug still live... I do that way:

      QObject* l_focusObject = qApp->focusObject();
      if (l_focusObject) {
          QString l_className = QString::fromUtf8(l_focusObject->metaObject()->className());
      
          if (!l_className.contains("Button", Qt::CaseInsensitive)) {
              qDebug() << "l_focusObject not button" << l_focusObject;
              l_focusObject = nullptr;
          }
      
          if (l_focusObject) {
              qDebug() << "l_focusObject disabled" << l_focusObject;
              l_oldValue = l_focusObject->property("enabled").toBool();
              l_focusObject->setProperty("enabled", false);
      
              connect(l_focusObject, &QObject::destroyed, l_intData.eventLoop, [&l_focusObject]() {
                  l_focusObject = nullptr;
                  qDebug() << "l_focusObject destroyed";
              });
          }
      }
      
      
      l_eventLoop->exec();
      
      if (l_focusObject) {
          qDebug() << "l_focusObject enabled" << l_focusObject;
          l_focusObject->setProperty("enabled", l_oldValue);
      }
      

      May be I have to put more classes to handle on l_className filter...
      How do you handle that?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved