PDA

View Full Version : how to know which QTextEdit i am using in tab widget



narlapavan
18th July 2012, 16:24
I have a tab widget with no pages in that.at run time i will add a page to tab widget and in that page i will create dynamic QTextEdit like this if i add another page in tab widget with dynamic QTextEdit for newly created page and so on.....

for example if i added four tabs(pages) in tab widget with dynamic QTextEdit for each page. If i want to access third tab(page) QTextEdit plain text i am using object of QTextEdit ->toPlainText(), when i am accessing this way, i am getting text from recently created dynamic QTextEdit which is under fourth tab.

Now the problem is how to access QTextEdit which is under page1 and how to access QTextEdit under page2 and so on....

please help me...............

wysota
18th July 2012, 16:30
You can store an array of those widgets somewhere, e.g. as a member variable of your form class.

narlapavan
18th July 2012, 16:35
i have QTextEdit *txtedit object. with txtedit object , when ever i am creating a new page i am creating new QTextEdit with same object i.e txtedit = new QTextEdit(); i can't differentiate this object

wysota
18th July 2012, 16:47
An array, or a vector, or a list...

such as QList<QTextEdit*>

sedi
18th July 2012, 16:49
as Wysota said: if your class has a member
QVector <QTextEdit*> myPages;
(e.g. in private: section of your header),
you can add and remove the pointers to your pages to it.
If you want to differentiate when using Signals and Slots, you can look the pointers up in your if you are inside your class.

Outside your class you can use the ->data() variables for identifying.
Therefore you setData(Qt::userRole+1) an identifying entry (e.g. QString: "Page1") at construction point of your pages.
When receiving a signal you can then look up sender().data(Qt::userRole+1).toString().

narlapavan
18th July 2012, 17:03
thank you problem solved

without inheriting QTextEdit how to use textchanged() signal

wysota
18th July 2012, 17:05
Exactly the same way as with inheriting. That has nothing to do with using signals.

Edder
18th July 2012, 17:27
I made a Tab class with all widgets i wanted in it and a name parameter and gave every widget a unique name and stored it in a QList<myTabClass*>.
The you may iterate through all Tabs and look up the name.