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.