I have already searched for similar questions but couldn't find anything related to this particular problem. If somebody has any idea, it would be very appreciated. :)
I am working on a image annotation tool (the annotation is made of landmarks to be positioned/dragged over the image). The image is being displayed in a subwindow (the main window has a MDI container). Inside the widget class that inherits the subwindow I am trying to create several instances of a FeatureWidget class (code bellow), inherited from QWidget and that will later be further coded to handle dragging and a couple of other things. The features are being stored in a std vector (std::vector), and I am not using pointers on purpose (I've implemented the copy constructor and assignment operator and intended to use vector.resize to handle changes in the number of features).
The problem is the following: if I create the features at the subwindow widget constructor, they are displayed as expected; however, if I create the features later on (when the open annotation file menu slot is called), the features are simply not shown at all. No error ocurr and the rest of the code works indeed ok (meaning I can even iterate the vector and log feature coordinates).
Just to point out: I already tested with pointer instances in the vector (i.e.: std::vector) and that seems not to be the problem. The feature widgets are being set with the same parent (the QLabel that displays the image).
Here are some snippets of the code:
FeatureWidget class:
class FeatureWidget: public QWidget { Q_OBJECT public: explicit FeatureWidget(QWidget *pParent = 0); FeatureWidget(const FeatureWidget &oOther); ~FeatureWidget(); FeatureWidget& operator=(const FeatureWidget &oOther); . . .
Widget class used in the MDI subwindow:
class ChildAnnotationWidget : public QWidget { Q_OBJECT private: std::vector<FeatureWidget> m_vFeatureWidgets; . . .
Method from subwindow widget that instantiates the feature widgets:
void ff::ChildAnnotationWidget::updateFeatureWidgets() { if(m_oTrainingSet.numFeatures() == 0) m_vFeatureWidgets.clear(); else { m_vFeatureWidgets.resize(m_oTrainingSet.numFeatures()); for(unsigned int i = 0; i < m_vFeatureWidgets.size(); i++) m_vFeatureWidgets[i].setParent(ui->lbImage); } }
Slot method from subwindow widget that opens the annotation file and redefines the feature widgets in the vector:
void ff::ChildAnnotationWidget::openAnnotation() { QString sFile = QFileDialog::getOpenFileName(this, tr("Open Annotation File"), ".", tr("Annotation Files (*.yaml)")); if(sFile.length()) { if(m_oTrainingSet.loadFromFile(qPrintable(sFile))) { m_sFileName = sFile; m_bChanged = false; updateFeatureWidgets(); showSample(1); updateStatusBar(); } else QMessageBox::critical(NULL, tr("Error Opening Annotation"), tr("It was not possible to open the annotation file. Please verify if the file format is correct."), QMessageBox::Ok); } }
The annotation file that I am using in the tests contains 76 features. As I said before, if I force the creation of those 76 features at the constructor (calling updateFeatureWidgets and passing the size as a parameter instead of getting from m_oTrainingSet.numFeatures), the features are correctly displayed. Otherwise, they are not.
Any ideas/suggestions?