Results 1 to 3 of 3

Thread: Static plugin: setting/reading a property

  1. #1
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Static plugin: setting/reading a property

    I created a static plugin following the examples of a Qt programming book, then I included it into my gui-application.

    The widget in the plugin show up fine, but I noticed that I can't access his properties in this way:
    Qt Code:
    1. IconEditorPlugin *m_editor;
    2. .. // initialize m_editor..
    3. int my_first_property = m_editor->property("zoomFactor").toInt();
    To copy to clipboard, switch view to plain text mode 

    It simply returns nothing.

    The plugin interface class is the following:
    Qt Code:
    1. class IconEditorPlugin : public QObject,
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. IconEditorPlugin(QObject *parent = 0);
    7.  
    8. QString name() const;
    9. QString includeFile() const;
    10. QString group() const;
    11. QIcon icon() const;
    12. QString toolTip() const;
    13. QString whatsThis() const;
    14. bool isContainer() const;
    15. QWidget *createWidget(QWidget *parent);
    16. };
    To copy to clipboard, switch view to plain text mode 

    and this is the real class of the widget with the properties I am trying to access to:
    Qt Code:
    1. class IconEditor : public QWidget
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor)
    5. Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage)
    6. Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor)
    7.  
    8. public:
    9. IconEditor(QWidget *parent = 0);
    10.  
    11. void setPenColor(const QColor &newColor);
    12. QColor penColor() const { return curColor; }
    13. void setZoomFactor(int newZoom);
    14. int zoomFactor() const { return zoom; }
    15. void setIconImage(const QImage &newImage);
    16. QImage iconImage() const { return image; }
    17. QSize sizeHint() const;
    18.  
    19. protected:
    20. void mousePressEvent(QMouseEvent *event);
    21. void mouseMoveEvent(QMouseEvent *event);
    22. void paintEvent(QPaintEvent *event);
    23.  
    24. private:
    25. void setImagePixel(const QPoint &pos, bool opaque);
    26. QRect pixelRect(int i, int j) const;
    27.  
    28. QColor curColor;
    29. QImage image;
    30. int zoom;
    31. };
    To copy to clipboard, switch view to plain text mode 

    I used the Q_PROPERTY macro as described, but now how to access them in the main application?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Static plugin: setting/reading a property

    zoomFactor is a property of the widget and not of the plugin.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    eg3gg (5th September 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Static plugin: setting/reading a property

    You're right, thanks

Similar Threads

  1. Controlling Property Setting Order
    By thePoet in forum Qt Tools
    Replies: 1
    Last Post: 13th July 2010, 19:29
  2. Replies: 2
    Last Post: 27th May 2010, 01:55
  3. Replies: 4
    Last Post: 5th March 2010, 14:20
  4. Designer plugin widget property not recognized
    By janus in forum Qt Programming
    Replies: 7
    Last Post: 14th April 2009, 21:26
  5. custom plugin designer property with out a variable?
    By high_flyer in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2006, 19:11

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.