Is it possible to get QToolBox widget's page name, in run time?
I have a QToolBox and adding pages to it in runtime
Each page has scroll area, inside scroll area comboboxes area dded at runtime
Is it possible to get page name of any particular combobox?
i tried code shown below, but it didnt work...
Code:
temp=dynamic_cast<QToolBox *>(tempCheckBox->parentWidget()->parentWidget());
QString fname
=temp
->itemText
(temp
->currentIndex
());
std::cout<<"FILE NAME:"<<fname.toStdString()<<endl;
also tried using
Code:
temp=dynamic_cast<QToolBox *>(tempCheckBox->parentWidget());
but program was crashing both time....
Re: Is it possible to get QToolBox widget's page name, in run time?
Well in your first example you are creating a memory leak. Beside that, are you sure tempCheckBox isn't a null pointer?
Re: Is it possible to get QToolBox widget's page name, in run time?
Ya thats not null pointer...
Re: Is it possible to get QToolBox widget's page name, in run time?
I tried as below….i got pointer to QToolBox….
But whenever i try to get page name of any widget it just returns nothing…always index is -1….:(
please tell me whats wrong here?
Code:
void FilterColl
::getParentPage(QCheckBox *tempCheckBox
) {
if(!tempCheckBox)
{
cout<<"no check box"<<endl;
return;
}
QWidget *parent
=tempCheckBox
->parentWidget
();
if(!parent)
{
cout<<"np page for this widget"<<endl;
return;
}
while(parent)
{ QString classname
=parent
->metaObject
()->className
();
cout<<"the parent class is:"<<classname.toStdString() <<endl;
if(classname=="QToolBox")
{ temp=dynamic_cast<QToolBox *>(parent);
std::cout<<"the tool box page name:"<<temp->itemText(temp->indexOf(tempCheckBox)).toStdString()<<endl;
cout<<"the index is :"<<temp->indexOf(tempCheckBox)<<endl;
}
parent=parent->parentWidget();
}
}
Re: Is it possible to get QToolBox widget's page name, in run time?
You are still producing a memory leak, and your code works if you fill the QToolBox correctly!
Code:
#include <QtGui>
{
if (!tempCheckBox) {
qWarning() << "no check box";
return;
}
QWidget *parent
= tempCheckBox
->parentWidget
();
if (!parent) {
qWarning() << "np page for this widget";
return;
}
while (parent) {
QString classname
= parent
->metaObject
()->className
();
qWarning() << "the parent class is:" << classname;
if (classname == "QToolBox") {
temp = dynamic_cast<QToolBox *>(parent);
qWarning() << "the tool box page name:" << temp->itemText(temp->indexOf(tempCheckBox));
qWarning() << "the index is :" << temp->indexOf(tempCheckBox);
}
parent = parent->parentWidget();
}
}
int main(int argc, char **argv)
{
tb.insertItem(0, &b, "sample text");
getParentPage(&b);
return 0;
}
gives
Quote:
the parent class is: "QWidget"
the parent class is: "QScrollArea"
the parent class is: "QToolBox"
the tool box page name: "sample text"
the index is : 0
the parent class is: "QWidget"
Re: Is it possible to get QToolBox widget's page name, in run time?
Quote:
Originally Posted by
Lykurg
You are still producing a memory leak,
Sorry i'm new to Qt, please let me how to avoid memory leak..?
Where i'm producing memory leak in this program?
any links to learn abt that?
Re: Is it possible to get QToolBox widget's page name, in run time?
Why you write ? There you create a tool box without deleting it. This creates a memory leak...