2

I want to have names for menu actions from sqlite database for QGIS Plugin dynamically.

       try:
            os.chdir(newPath)
            con = sqlite3.connect("db.sqlite")

            cur=con.cursor()
            cur.execute("""select queryLabel from custom_query;""") 
            cursor=cur.fetchall()
            for row in cursor:
                self.menu = QMenu( row[0], iface1.mainWindow().menuBar() )
                self.menu.setObjectName( row[0] )
                self.actionAttribute_Data=self.menu_WB_Query.addAction(row[0])
                #self.actionAttribute_Data.triggered.connect(self.attribute_data) 
        except sqlite3.Error, e:
            if con:
                con.rollback()
                print "Error %s:" % e.args[0]
                #sys.exit(1)
        finally:
            if con:
                con.close()

Putting this in initgui() I achieved the desired output, but as initgui() is called only once, the menu actions don't get refreshed if db is edited during execution of plugin.

1
  • Good and clear question. Have you tried qgis.utils.reloadPlugin('myplugin'). Take a look at gis.stackexchange.com/questions/119418/…. Hope you editing the db from within the plugin, since I see now way of popping an event from db to plugin.
    – Jakob
    Commented Nov 7, 2017 at 8:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.