PDA

View Full Version : Question about QMetaMethod



jlbrd
5th August 2006, 22:12
Hi,

I want for Qt widgets list all signals with parameters. For this I use :


QLineEdit *line = new QLineEdit;
for(int i=0; i<line->metaObject()->methodCount(); i++)
{
QMetaMethod meta = line->metaObject()->method( i );
if( meta.methodType() == QMetaMethod::Signal )
qDebug() << meta.signature() << meta.parameterTypes() << meta.parameterNames();
}

The result of the example above is :


destroyed(QObject*) ("QObject*") ("")
destroyed() () ()
customContextMenuRequested(QPoint) ("QPoint") ("pos")
textChanged(QString) ("QString") ("")
textEdited(QString) ("QString") ("")
cursorPositionChanged(int,int) ("int", "int") ("", "")
returnPressed() () ()
editingFinished() () ()
selectionChanged() () ()
lostFocus() () ()

The problem is for textChanged, textEdited etc. Indeed the type parameters is present but not the names whereas for customContextMenuRequested the name "pos" is present.

Then why for certain signals the names are present and for others not ?
I would like to have all the names !

Thanks

jacek
5th August 2006, 22:16
Then why for certain signals the names are present and for others not ?

qlineedit.h:

...
Q_SIGNALS:
void textChanged(const QString &);
...

qwidget.h:

Q_SIGNALS:
void customContextMenuRequested(const QPoint &pos);

Now you see why?

jlbrd
5th August 2006, 22:25
Thanks you,
Yes I understand why.
My error it is that in Documentation, the names are present. Examble, textChanged appear :

void QLineEdit::textChanged ( const QString & text )

Certain parameters are regarded as "useless" since the name is not present in the header ?

jacek
5th August 2006, 22:30
Certain parameters are regarded as "useless" since the name is not present in the header ?
No, you just don't have to provide parameter names in headers.

jlbrd
5th August 2006, 22:42
You are right. It is not necessary to put the names of the parameters but :

1. Why write certain names and not others on headers.
2. Especially why create a function which is not always useful ( QMetaMethod:: parameterNames()).

jacek
5th August 2006, 22:54
Why write certain names and not others on headers.
Because there are many developers and some write signal parameter names and some don't? I think that simply nobody thought that somebody might need them.


Especially why create a function which is not always useful ( QMetaMethod:: parameterNames()).
Actually all functions aren't always useful.

If you really concerned about this, send a suggestion to the Trolls that they should add missing parameter names or even create a patch for it.

jlbrd
5th August 2006, 23:16
Ok thank you,for your information, I explain why I need some (even if you cannot help me !) :

I work on QIde, a IDE for Qt4. With a right click, one will be able to create a subclass of a form (ui). In a dialog (see screenshot), I list signals for each widgets. When the user valid the dialog, each items checked are created on a new implementation file with his name, parameter types and names. It is for that that I need the names!

Thanks,