For example, is there any potential risk in the following code?
// when re-implement QCalendarWidget's functions
QObjectList children_of_this = this->children();
//this points to QCalendarWidget
for( int i = 0; i < children_of_this.count(); i++)
{
if(children_of_this.at(i)->objectName() == "qt_calendar_navigationbar")
{
navigator = qobject_cast<QWidget*>(children_of_this[i]);
if(navigator)
{
// do something to navigator's layout
}
//navigator is a pointer to a QWidget, which is previous NULL
if(children_of_this.at(i)->objectName() == "qt_calendar_calendarview")
{
view = qobject_cast<QTableView*>(children_of_this[i]);
if(view)
{
view->setItemDelegate(new QStyledItemDelegate);
}
}
//view is a pointer to a QTableView which is previous NULL
}
// when re-implement QCalendarWidget's functions
QObjectList children_of_this = this->children();
//this points to QCalendarWidget
for( int i = 0; i < children_of_this.count(); i++)
{
if(children_of_this.at(i)->objectName() == "qt_calendar_navigationbar")
{
navigator = qobject_cast<QWidget*>(children_of_this[i]);
if(navigator)
{
// do something to navigator's layout
}
//navigator is a pointer to a QWidget, which is previous NULL
if(children_of_this.at(i)->objectName() == "qt_calendar_calendarview")
{
view = qobject_cast<QTableView*>(children_of_this[i]);
if(view)
{
view->setItemDelegate(new QStyledItemDelegate);
}
}
//view is a pointer to a QTableView which is previous NULL
}
To copy to clipboard, switch view to plain text mode
and in the "qcalendarwidget.cpp", the Qt's source code:
//i want to access objects like this
d
->m_view
->setObjectName
(QLatin1String("qt_calendar_calendarview"));
navBarBackground
= new QWidget(widget
);
navBarBackground
->setObjectName
(QLatin1String("qt_calendar_navigationbar"));
//i want to access objects like this
d->m_view->setObjectName(QLatin1String("qt_calendar_calendarview"));
navBarBackground = new QWidget(widget);
navBarBackground->setObjectName(QLatin1String("qt_calendar_navigationbar"));
To copy to clipboard, switch view to plain text mode
I'm quite new to both Qt and C++ and wondering whether or not it is right to get the objects pointers those are not exposed to users.
Bookmarks