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. "triggered()" Signal for Menu Item is being sent on App start up
Qt 6.11 is out! See what's new in the release blog

"triggered()" Signal for Menu Item is being sent on App start up

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.7k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    StabbAmonte
    wrote on last edited by
    #1

    I am just starting developing/evaluating QT and I am seeing a weird issue. I have a very simple application, currently its a window with a single Menu Item. I created this in the QT Designer and generated a python file with pyuic4. The QT Designer has no signal/slots defined. Here part of the generated code in question:

        self.actionLoad_Dev_Defs = QtGui.QAction(MainWindow)
        self.actionLoad_Dev_Defs.setObjectName(_fromUtf8("actionLoad_Dev_Defs"))
        self.menuFile.addAction(self.actionLoad_Dev_Defs)
    

    I have another file that creates an instance of my generated class and attempts to setup a Signal to that Menu Item

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.actionLoad_Dev_Defs.connect(self.ui.actionLoad_Dev_Defs, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT(self.loadDefinitions()))
    

    The problem is that self.loadDefinitions() is being called immediately when the application starts.
    Any help is appreciated.
    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      If my PyQt is not to rusty, you should change your SLOT to QtCore.SLOT(self.loadDefinitions)

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        StabbAmonte
        wrote on last edited by
        #3

        I tried that and it caused this error.

        File "/Users/sabbamonte/Dev/MainWindow.py", line 12, in init
        self.ui.actionLoad_Dev_Defs.connect(self.ui.actionLoad_Dev_Defs, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT(self.loadDefinitions))
        TypeError: SLOT(str): argument 1 has unexpected type 'method'

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Are you using PyQt or PySide ?

          If the first one: here is the guide to setup your signals and slots using the new syntax

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            StabbAmonte
            wrote on last edited by
            #5

            I was looking at this page for a while and I am not trying to create a new Signal I am trying to connect to the signal of an already created Menu Item. Also when I look at the signature for the connect function in QObject.py it looks like this:

            def connect(self, QObject, SIGNAL, *args, **kwargs):

            There is no connect function that takes a single argument. I am using Python 3.4.3 and QT 4.11.5

            1 Reply Last reply
            0
            • S Offline
              S Offline
              StabbAmonte
              wrote on last edited by StabbAmonte
              #6

              I figured out the problem if anyone comes accross this thread I hope this helps.

                  self.ui.actionLoad_Dev_Defs.connect(self.ui.actionLoad_Dev_Defs, QtCore.SIGNAL("triggered()"), self.loadDefinitions)
              

              no need for the QtCore.SLOT(. . . ) on that third param

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Good !

                Since you have it working now, please update the thread title prepending [solved] so other forum users my know a solution has been found :)

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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