Jump to content

Recommended Posts

Posted (edited) · Basic trouble with Qt slot

I'm trying to develop a Cura extension, while, at the same time, figuring out Qt.  Unfortunately, I'm struggling with something that seems like it should be very basic and can't figure out where I'm going wrong.

 

Essentially, I want to display a dialog and call a Python function when the dialog is accepted. 

 

My understanding is that, by decorating a function with the @pyqtSlot decorator, it should be callable from my QML.  However, attempting to do this results in a complaint that my decorated Python function "is not a function".  What I'm doing seems to match what I've seen in other plugins and online, but it's just not working.

 

Here's the Python code that's not working:

 

import os.path
from PyQt5.QtCore import QObject, pyqtSlot

from UM.Application import Application
from UM.Extension import Extension
from UM.Logger import Logger
from UM.PluginRegistry import PluginRegistry

class TempTower(Extension):
    def __init__(self):
        super().__init__()

        # Add menu items for this plugin
        self.setMenuName("TempTower")
        self.addMenuItem("Generate a Temp Tower", self._showTempTowerDialog)

        # The dialog is generated the first time it's needed
        self._settingsDialog = None

    ##  Creates a modal dialogue with information about the selection.
    def _createDialogue(self, filename):
        qml_file_path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), filename)
        component = Application.getInstance().createQmlComponent(qml_file_path, {"manager": self})
        return component

    def _showTempTowerDialog(self):
        if self._settingsDialog is None:
            self._settingsDialog = self._createDialogue("test.qml")
        self._settingsDialog.show()
        Logger.log('d', 'Dialog dismissed')

    @pyqtSlot()
    def tempTowerDialogAccepted(self):
        Logger.log('d', 'Dialog was accepted')

 

And the corresponding QML file:

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1

import UM 1.1 as UM

UM.Dialog
{
    id: dialog

    rightButtons: Button
    {
        text: "Generate"
        onClicked:
        {
            manager.tempTowerDialogAccepted()
            dialog.accept()
        }
    }
}

 

When I click the "Generate" button in the QML dialog, Cura displays the following error (snipped somewhat for clarity):

file:/TempTower/test.qml:23: TypeError: Property 'tempTowerDialogAccepted' of object QVariant(PyQt_PyObject, ) is not a function

 

Can anyone give me a hint as to what I'm doing wrong here?  It's embarrassing, but I simply cannot figure this out.

Edited by bradk3
Added a bit more explanation.
  • Link to post
    Share on other sites

    Posted · Basic trouble with Qt slot

    *Sigh*  Never mind.  It looks like my problem was not inheriting from QObject.  I Changed the class definition to this:

     

    class TempTower(QObject, Extension):

     

    And it seems to work now.

    • Like 1
    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • Help Us Improve Cura – Join the Ultimaker Research Program
        🚀 Help Shape the Future of Cura and Digital Factory – Join Our Power User Research Program!
        We’re looking for active users of Cura and Digital Factory — across professional and educational use cases — to help us improve the next generation of our tools.
        Our Power User Research Program kicks off with a quick 15-minute interview to learn about your setup and workflows. If selected, you’ll be invited into a small group of users who get early access to features and help us shape the future of 3D printing software.

        🧪 What to Expect:
        A short 15-minute kickoff interview to help us get to know you If selected, bi-monthly research sessions (15–30 minutes) where we’ll test features, review workflows, or gather feedback Occasional invites to try out early prototypes or vote on upcoming improvements
        🎁 What You’ll Get:
         
        Selected participants receive a free 1-year Studio or Classroom license Early access to new features and tools A direct voice in what we build next
        👉 Interested? Please fill out this quick form
        Your feedback helps us make Cura Cloud more powerful, more intuitive, and more aligned with how you actually print and manage your workflow.
        Thanks for being part of the community,

        — The Ultimaker Software Team
        • 0 replies
      • Cura 5.10 stable released!
        The full stable release of Cura 5.10 has arrived, and it brings support for the new Ultimaker S8, as well as new materials and profiles for previously supported UltiMaker printers. Additionally, you can now control your models in Cura using a 3D SpaceMouse and more!
          • Like
        • 18 replies
    ×
    ×
    • Create New...