PDA

View Full Version : qtreewidget accessing data from another qtreewidget



MurDoK
18th October 2007, 00:51
Hello. This is not exactly my problem, I have simplified it but it should be worth.

I have a QMainWindow with two QTreeWidgets.
I have subclassed QTreeWidgets: MyTree1 and MyTree2, each one has its own ContextMenu when you right click on.

Now I want to click on MyTree2 and in the ContextMenu I choose "Text of the first item" that it's used to debug and prints on console the text of the first QTreeWidgetItem of MyTree1.
That should be too easy to do but since QMainWindow has a (QWidget)centralwidget and you can't remove it I don't know how to do that.

It should be something like this:


#include "mytree2.h"

MyTree2::MyTree2(QWidget* parent)
: QTreeWidget(parent)
{
[...]
p = parent->parentWidget(); //since p is a pointer
//to the parent widget which is centralwidget
//I also use parentWidget() to point to QMainWindow
}

MyTree2::debugFirst()
{
qDebug() << p->QTreeWidget1->topLevelItem(0)->text(0);
}



But an error compiling in line 14 says that Class QWidget doesnt own a member called QTreeWidget1

So.. how could I do that?
I hope you guys understand me :rolleyes: and I'm sorry if this question is too newbie for the newbie forum :o

MurDoK
19th October 2007, 01:29
Ok, I have found the solution.
All what I needed is to declare the function as static and I had never used it.
I found the answer in this forum but now I can't find the exact thread.
:)