Hi,
in many QT methods, for example the data() method of QAbstractTableModel (and many others) I am creating objects on the stack and returning them, like this:
Action *a;
int row_num,col_num;
col_num=index.column();
row_num=index.row();
if (row_num>
=actions
->count
()) return (QVariant());
a=actions->value(row_num);
if (a==0) {
}
if (role==Qt::DecorationRole) {
if (col_num==0) {
cat_action_id_t act_code;
act_code=a->get_action_code();
switch(act_code) {
case CAT_ACTION_UNDEFINED: {
break;
}
case CAT_ACTION_COMMENT : {
QPixmap icon
("/home/action_type_icons/comment.png");
return(icon);
break;
}
case CAT_ACTION_NEW_DEPENDENCY: {
QPixmap icon
("/home/action_type_icons/new_dependency.png");
return(icon);
break;
}
QVariant ActionListModel::data(const QModelIndex &index, int role) const {
Action *a;
int row_num,col_num;
col_num=index.column();
row_num=index.row();
if (row_num>=actions->count()) return (QVariant());
a=actions->value(row_num);
if (a==0) {
return(QVariant());
}
if (role==Qt::DecorationRole) {
if (col_num==0) {
cat_action_id_t act_code;
act_code=a->get_action_code();
switch(act_code) {
case CAT_ACTION_UNDEFINED: {
break;
}
case CAT_ACTION_COMMENT : {
QPixmap icon("/home/action_type_icons/comment.png");
return(icon);
break;
}
case CAT_ACTION_NEW_DEPENDENCY: {
QPixmap icon("/home/action_type_icons/new_dependency.png");
return(icon);
break;
}
To copy to clipboard, switch view to plain text mode
The "icon" variable is created on the stack and is destroyed after the method execution ends, but I am not getting segmentation faults in my app. The question is, how does it work ? Is QT copying all objects I am returning in the QT methods that I am overriding?
TIA.
Bookmarks