Results 1 to 5 of 5

Thread: QApplication Instance Error

  1. #1
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default QApplication Instance Error

    Im having issues implementing my little window into a full Qt Application. Let me explain...
    im using NUKE (by the foundry) that is built using PyQt/PySide. Im builing just a quick dialog that pops up and lets you choose stuff.
    I've built other dialogs and they work fine.

    this current project tell me : "A QApplication instance already exisits"

    this is where the problem is, i think:
    Qt Code:
    1. def ElementBrowserShow():
    2. app = QApplication(sys.argv)
    3. window = MainDialog()
    4. window.show()
    5. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    When I omit the 2nd line, i get an error on the 5th line where "app" is not defined. if i also omit the 5th line, the dialog flashes on and then quits.
    i read that i can implement app = QtGui.QApplication.instance(), but it doesnt work either. Not sure if im using it correctly.

    Qt Code:
    1. def ElementBrowserShow():
    2. app = QtGui.QApplication.instance()
    3. window = MainDialog()
    4. window.show()
    5. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QApplication Instance Error

    "A QApplication instance already exists"
    Doesn't that tell you exactly what the problem is? Somewhere in your code (or the foundry, whatever that is), a QApplication instance has already been created. You've posted only a tiny fragment of code which looks like it might be a slot of some sort, and if it is, then it won't be executed unless it has been connected to a signal and that signal has been fired via an event loop running in a QApplication (usually) instance. That fact that it is being called says that is exactly the case.

  3. #3
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QApplication Instance Error

    I figured out the issue, and solution. Nuke doesn't allow multiple instances.
    I had to omit line 1, 2, and 5.

    Not sure exactly why this works...but Nuke had issues calling those lines from inside a function. So instead of calling the function, I just call window.show()

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QApplication Instance Error

    Nuke doesn't allow multiple instances.
    No, it is the Qt runtime that doesn't allow multiple QApplication instances. Nuke uses Qt and created the QApplication instance when it started up. If you are adding PyQt code to be used within Nuke, then you cannot create another QApplication instance, but must use the one already created.

  5. #5
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QApplication Instance Error

    Yes, thank you! That's what I meant to say, but couldn't find the right words.

Similar Threads

  1. Replies: 2
    Last Post: 1st August 2011, 07:30
  2. Getting QApplication instance from the executable
    By nikhilqt in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2009, 11:16
  3. QApplication focus from other friend instance
    By patrik08 in forum Qt Programming
    Replies: 0
    Last Post: 9th June 2008, 13:42
  4. Share QApplication instance (exe and dll)
    By cquinones in forum Qt Programming
    Replies: 11
    Last Post: 18th October 2007, 19:10
  5. QApplication instance
    By nile.one in forum Qt Programming
    Replies: 9
    Last Post: 5th October 2007, 13:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.