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. [SOLVED] QMetaObject::connectSlotsByName not working for QDialog::accepted()
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QMetaObject::connectSlotsByName not working for QDialog::accepted()

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.4k Views 1 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.
  • D Offline
    D Offline
    Danielc
    wrote on last edited by
    #1

    Hi everyone!

    Before everything, thanks for reading.

    I am developing an application using Qt (and Qt Creator). I use the Auto-connect feature and it works pretty well for many signals, but right now I have a problem with the signal accepted() of a QDialog.

    I checked the QDialog's ObjectName (PropertyForm) and it's fine. I tried to make the slot "on_PropertyForm_accepted()" public, but it does not work.

    Here is the related code fragment:

    In "propertyform.h"

    @namespace Ui {
    class PropertyForm;
    }

    class PropertyForm : public QDialog
    {
    Q_OBJECT

    public:
    explicit PropertyForm(QWidget *parent = 0);
    ~PropertyForm();
    void setPropertyValue(const QString& key, const QString& value);
    QHash<QString, QString> getProperties() const;
    void savePropertyValues();

    public slots:
    void propertyAdded(const QString& name, const QString& key);
    void propertyRemoved(const QString& key);
    void clearAllValues();
    void on_PropertyForm_accepted();

    private:
    Ui::PropertyForm *ui;
    QHash<QString, int> keyIndex;
    QHash<QString, QString> properties;

    int findRowWithKey(const QString& key);
    void rebuildIndex();
    

    };@

    In "propertyform.cpp":

    @void PropertyForm::on_PropertyForm_accepted()
    {
    savePropertyValues( );
    }@

    It compiles without problems, but I get "QMetaObject::connectSlotsByName: No matching signal for on_PropertyForm_accepted()" in Application Output. Also, if it helps, I create three private variables of this class in my main window.

    Any suggestions?

    Thanks!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      PropertyForm is your class. the autoconnect connects objects signals with your slots.

      the logic is:

      on_<sender name>_<signal name>

      sender name is the name of the sender object, not a class name.
      signal name is the name of the signal to connect.

      as you just want to do some special things during accept, overewrite "accept()":http://doc.qt.nokia.com/4.7/qdialog.html#accept virtual function. That's what it is for :-)

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Danielc
        wrote on last edited by
        #3

        Hi and thanks for replying!

        Yeah, it makes sense.. I followed your advice and overwrote accept() (in fact I think it is more efficent). Anyway, I would like to know if it is possible to use auto-connect feature for the current instance of the class, something like on_this_accepted(). I know you can achieve something like that outside the class (in the parent), but it wouldn't be good if you have to repeat the methods for each instance of the class. Maybe it can be done manually (using connect()), but not with auto-connect.

        Also, Qt Creator generated that slot, so I think it is a bug, isn't it?

        Thanks again and greetings!

        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