Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Chicken-and-egg problem with exec()

Chicken-and-egg problem with exec()

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • B Offline
    B Offline
    bovilexic
    wrote on last edited by
    #1

    Greetings -

    Mac question...

    I have a non-Qt application, which utilizes a Qt app as a "plugin" of sorts: when a user hits a button in the main (non-Qt) app, it calls some code that creates a QMainWindow, then calls show() and exec():

    @
    static QApplication a(argc, argv);
    static MainWindow editor;
    editor.show();
    a.exec();
    @

    Once the user hits OK or Cancel in this dialog-type MainWindow, the GUI goes away, and control returns to the main application. Works just fine on Snow Leopard. On Lion, however, the Qt "editor" window does not appear, until the user clicks the main (non Qt) app's icon in the Dock. Indeed, prior to clicking on said Dock icon, I can use Command-Tab, and see that the Finder is the current/active/front application (the main non-Qt program should be the active app, as it is on Snow Leopard). My idea for a workaround is to use SetFrontProcess() to again make the main app current, and this should make my Qt dialog appear.

    However, doing so before calling "exec()" does not work, which is not surprising. I think I need to somehow call SetFrontProcess() after exec(). But of course exec() does not return until the dialog exits. So, my question is this: in my MainWindow "application", I would like to try calling SetFrontProcess() as soon as possible in the event-handling. Obviously the show() method is too early, but what can I hook into that happens right off once exec() launches the MainWindow?

    Thanks...

    • Philip
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      You can use a QTimer::singleShot() with a timeout of 0 to invoke a slot as soon as event processing happens in your main loop.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bovilexic
        wrote on last edited by
        #3

        Thanks - I'll give that a shot, so to speak :-)

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bovilexic
          wrote on last edited by
          #4

          Turns out the SetFrontProcess() doesn't actually work, even when calling it after the widget is "running". Ended up using AppleScript:

          @
          QString aScript =
          "tell me\n"
          " activate\n"
          "end tell\n";

              QString osascript = "/usr/bin/osascript";
              QStringList processArguments;
              processArguments << "-l" << "AppleScript";
              
              QProcess p;
              p.start(osascript, processArguments);
              p.write(aScript.toUtf8());
              p.closeWriteChannel();
              p.waitForFinished();
          

          @

          Go figure...

          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