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] Emiting QTreeWidget currentItemChanged event
QtWS25 Last Chance

[SOLVED] Emiting QTreeWidget currentItemChanged event

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.5k Views
  • 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.
  • L Offline
    L Offline
    lloydqt
    wrote on last edited by
    #1

    Hi,

    I have a class named MyClass, inside that there are two objects - QTreeWidget, and QTableWidget. When an item in QTableWidget is double clicked, I need to fire a QTreeWidget "currentItemChanged" signal. My pseudo code looks like this...

    @
    Myclass::Myclass()
    {
    connect(MyTreeObject,SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
    this,SLOT(TreeItemSelected(QTreeWidgetItem*)));
    connect(MyTableObject,SIGNAL(cellDoubleClicked(int,int)),
    this,SLOT(TableItemDoubleClicked(int,int)));
    }

    void Myclass::TreeItemSelected(QTreeWidgetItem*)
    {
    //do something
    }

    void Myclass::TableItemDoubleClicked(int r,int c)
    {
    //emit currentItemChanged signal of the MyTreeObject
    .....
    }
    @

    Whats the right method to emit the signal in this case?

    Thanks Lloyd

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

      You cannot emit signals from outside a class[1]. What you can do, is sublcass the QTreeWidget, then, in MyClass, connect the table widget's cellDoubleCliced signal to that slot and have that slot emit the currentItemChanged signal.

      fn1. In fact, the "signals" pseudo keyword is just a macro and eventually translates to "private".

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lloydqt
        wrote on last edited by
        #3

        Thanks Volker, that solved my problem partially.

        I was expecting that, if emit a "currentItemChanged" event, the selection in the tree control would also change. But that didn't happen!

        This arises a question in mind that, is there any use for "emit" ?, without that also I can accomplish the task by a simple function call

        Thanks,
        Lloyd

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          No, that doesn't work, as it is just the other way round: A signal is fired when something happened - e.g. the current item changed and the currentItemChanged() signal is emitted. If you want something to happen, you call a slot. In your case, you can call setCurrentItem() on the tree view.

          The use of emit is in your own classes. In case something interesting happened, you emit a signal. Other classes connect to it and behave accordingly.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lloydqt
            wrote on last edited by
            #5

            Thanks Volker, now I am clear :)

            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