Qt World Summit: Register Today!

Qt creater SIGNAL question

  • hi every body . i have one question . why some times in qt creator doesnt display all signal of one object ? is that one bug in creator ?
    for example 'QStandardItemModel' does have about 20 signals but in qt creator when i write
    @ QObject::connect(model, SINGAL(.... @ display about 6 signals of 'QStandardItemModel' ! i see this problem for QStateMachine and report it.
    tnx for help

  • now 'modelReset()' one signal of model and works ! but doesnt display to list of SIGNAL() !

  • Moderators

    Look at the documentation of those signals (http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#signals ) -- many of them say:

    bq. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

    Those signals are private and can only be emitted by QAbstractItemModel. They are not displayed in QtCreator because QStandardItemModel is not allowed to emit them.

    [quote author="ahura_24" date="1344118300"]now 'modelReset()' one signal of model and works ![/quote]

    That's interesting! modelReset() is supposed to be one of the private signals, according to the source code (http://qt.gitorious.org/qt/qt/blobs/4.8/src/corelib/kernel/qabstractitemmodel.h ). Can you show us your code where you tested modelReset()? How does it work?

  • @
    int main(int argc, char **argv)
    QApplication app(argc, argv);

    QStandardItemModel m;
    QLabel l("asdfasdf");
    QObject::connect(&m, SIGNAL(modelReset()), &l, SLOT(clear()));
    return app.exec();


    in debug mode if signal or slot doesnt exist show warning message but in this code doesnt display warning and works correctly .

    how can i define private signals ?
    if these signals are private , why in assistant write 18 signals 'inherit' from QAbstractItemModel ?
    private member doesnt inherit in 'public inheritance' !

  • Moderators

    Ah, sorry... I was mistaken earlier. There's no such thing as a "private signal" -- all signals are publicly visible.

    What's happening is: Subclasses of QAbstractItemModel are not allowed to EXPLICITLY emit some of the inherited signals, which means that subclass code must not contain "emit columnsAboutToBeChanged()". If the subclass wants to emit those signals, it must call QAbstractItemModel's protected functions, e.g.

    MyModel : public QAbstractItemModel
    // ...

    void wrongFunction() {
        emit columnsAboutToBeInserted(); // DISALLOWED
        // ...
        // Code to insert columns
    void correctFunction() {
        beginInsertColumns(); // This function is inherited from QAbstractItem model, and will emit columnsAboutToBeInserted()
        // ...
        // Code to insert columns


    If I try to compile the code above, my compiler will complain in line #6 that columnsAboutToBeInserted() is private. But, the signals are not really private: my model must still emit the signal before inserting data, so that my application can prepare properly.

    So, we have an answer to your original post: Those signals are marked as "private" to prevent wrong code from compiling (like my example above). But, that approach made QtCreator consider them private functions, and hide them from the list of available signals.

    I guess QtCreator SHOULD display those signals. Do you want to file a bug report?

  • yes i report this bug.
    i have another question . why in some class we have 'setTextAlignment' and some other class 'setAlignment' ?
    for example in 'QLabel' has 'setAlignment' but 'QTableWidgetItem' has 'setTextAlignment' ! it create one inconsistency for name of functions !!

  • Moderators


    QTableItemWidgetItem::setTextAlignment() controls text only.
    QLabel::setAlignment() controls text or images or movies.

    They have different functions, so they have different names.

    By the way, if you have a new question, it's good to start a new topic so that other people who are interested can find it :)

Log in to reply