Toolbar's Action Disable Problem [SOLVED]



  • Hello guys.

    I want to disable a toolbar button sometimes. I mean toolbar button is unclickable and visible. I look for the internet but I cant find the solution.

    This code crush my program.
    @filterAction->setEnabled(false);@

    createActions()
    @filterAction = new QAction(tr("&Filter Data"), this);
    filterAction->setIcon(QIcon("filter.ico"));
    connect(filterAction, SIGNAL(triggered()), this, SLOT(filterData()));
    ...
    @

    createToolbars()
    @QToolBar *toolbar;
    toolbar = addToolBar(tr("Processes"));
    toolbar->addAction(filterAction);
    ...
    @



  • I suggest to use this instead:

    @connect(filterAction, SIGNAL(triggered(bool)), this, SLOT(filterData()));@

    and this conection for the slot:

    @if (checked)
    filterAction->setEnabled(true);
    else
    filterAction->setEnabled(false);@



  • don't forget to add:

    @filterAction->setCheckable(true);@


  • Moderators

    @mbnoimi:
    He wanted to know how to "disable ":http://qt-project.org/doc/qt-4.8/qaction.html#enabled-propan action not to make it checkable. So i think this is not what the intended.

    [quote author="kingsta" date="1367141772"]
    This code crush my program.
    @filterAction->setEnabled(false);
    [/quote]
    What do you mean with "crush"? You program crashes when you do this? If so make sure that the pointer has been already initialized.



  • [quote author="mbnoimi" date="1367142196"]I suggest to use this instead:

    @connect(filterAction, SIGNAL(triggered(bool)), this, SLOT(filterData()));@
    [/quote]

    Okey. I changed the code. I dont know the different between triggered() and triggered(bool). Can you tell to me?

    [quote author="raven-worx" date="1367143959"]
    What do you mean with "crush"? You program crashes when you do this? If so make sure that the pointer has been already initialized.
    [/quote]

    You totally right. I realize I have a pointer problem. I fix it. It works.

    I have a question. How can i connect the toolbar view changing?
    I write that code but I got the message;
    @ QObject::connect: Cannot connect (null)::visibilityChanged(bool) to MainWindow::controlToolBarView()@

    code
    @ connect(toolbar, SIGNAL(visibilityChanged(bool)), this, SLOT(controlToolBarView()));
    @


  • Lifetime Qt Champion

    triggered(bool) is for when your tool button is checkable. The parameter tells you where you checked it (true) or unchecked it.

    The error message says that your connecting a NULL pointer. Are you sure you toolbar variable points to a valid QToolbar when calling connect ?



  • [quote author="SGaist" date="1367185839"]triggered(bool) is for when your tool button is checkable. The parameter tells you where you checked it (true) or unchecked it.

    The error message says that your connecting a NULL pointer. Are you sure you toolbar variable points to a valid QToolbar when calling connect ?[/quote]
    You right. I fix the error.

    Thank all of you guys.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.