0

Hi all to start off with:

Coding in C++

Using QT Creator version 5.4.1

So I'm having a problem with my program when I start constructing new classes with some member variables, my program crashes. I've tried assigning values to them, in the header, in the class constructor and in the class initialization neither is helping. These are what I figure are causing the problem:

The class is called WfsFeatureViewer uses a header file and a Qt Ui file. The Ui is initialized on construction.

std::vector<CustomLineItem*> m_line_items;
std::vector<CustomPointItem*> m_point_items;
std::vector<CustomPolygonItem*> m_polygon_items;

They are simple Polygon/Line/Point items that are subclassed from QGraphicsPolygonItem,PointItem and line item. Nothing much too them. If I exclude these guys from my class it doesn't crash (but its vital they are member variables for this class)

I'm Wondering if its the speed I'm creating the class at? Normally I get about 5-60 of these and it crashes. The WfsFeatureViewer class gets added to a QListWidgetView. So using a loop creates a bunch of them for the user to see. Here's how it looks:

// I used for index to pass the the WfsFeatureViewer
int i = 0;

// Loop for all the WFS Feature names and elements
for(auto feature_itr : m_layer_elements)
{
    // Increment I per loop
    i++;

    // Create a new WfsFeatureViewer
    auto wfs_viewer(new WfsFeatureViewer());

    QObject::connect(wfs_viewer,&WfsFeatureViewer::sendNewShps,this,&DialogWfsReader::catchNewShps);

    //Set some UI data and base WFS for later reading.
    wfs_viewer->setElementAndName(feature_itr.first,feature_itr.second);
    wfs_viewer->setIndex(i);
    wfs_viewer->setWfsBaseURL(m_ui->m_line_wfs_name->text().toStdString());

    // Loop to get the layer count for this wfsViewer
    for(auto layer_itr : m_layer_count)
    {
        // check if its the correct name
        if(layer_itr.first == feature_itr.first)
        {
            // Set the layer count
            wfs_viewer->setLayerCount(layer_itr.second);
        }
    }
    // loop to get the shape type
    for(auto shp_itr : m_layer_shp_type)
    {
        // check if its the correct name
        if(shp_itr.first == feature_itr.first)
        {
            // set the shape type
            wfs_viewer->setShapeType(shp_itr.second);
        }
    }

    // Create a new QListWidgetItem
    QListWidgetItem* item(new QListWidgetItem);

    // Add it to the QListWidget
    m_ui->m_list_layers->addItem(item);

    // Set the wfs_viewer onto the item
    m_ui->m_list_layers->setItemWidget(item,wfs_viewer);

    // Give it a size
    item->setSizeHint(QSize(100,210));

    // And adjust the UI
    wfs_viewer->adjustSize();
}

So this can loop for quite a few times, meaning lots of new objects getting created, comes out to be about 10-30MB of ram if i load about 70-100 classes in.

I'm not too sure whats causing this, also im not getting a Heap error so I know I'm not killing the heap.

Jake Wade
  • 571
  • 3
  • 19

1 Answers1

0

Okay I've seemed to have fixed it now, stops crashing once when creating new Classes. A full Clean, QMake and rebuild fixed the issue. Not too sure what was causing it. But its fixed now, will post something here again if I find an proper answer to this solution.

Jake Wade
  • 571
  • 3
  • 19
  • I've had this issue a bunch of times. Re running QMake usually solves it. If it's a syntax or code related issue the debugger output usually tells you which line is causing it (though the output is messy). – Andrew Jun 12 '15 at 01:35
  • Yeah its kind of irritating but ah well. Do you know why this happens? Or is it just another random Qt bug? – Jake Wade Jun 12 '15 at 07:33
  • Probably has something to do with the MOC and converting your QtC++ class to "real" C++. Just needs to be refreshed manually sometimes.You can see similar behavior when including new modules in your project file. (Ex QT += concurrent) and then using the class without having closed the pro file forcing a rescan / reindex. Whenever weird thigns start to happen in Qt i just clean > qmake > build which generally solves it. (Unless i've done something extra dumb that is!) – Andrew Jun 13 '15 at 15:48