2013-07-25 7 views
5

को हटा नहीं देता है यह क्यूटी ui फ़ाइल से उत्पन्न कोड है, मुझे लगता है कि कोड स्मृति आवंटित करने के लिए new कीवर्ड का उपयोग करता है लेकिन आवंटित संसाधन को हटाने के लिए कक्षा में delete कीवर्ड नहीं है, यह गलती है क्यूटी डेवलपर्स या कुछ और है (कोई अस्वीकृत संसाधन नहीं)?क्यूटी यूआई जनरेटर संसाधन

/******************************************************************************** 
** Form generated from reading UI file 'canyyeffectcontrol.ui' 
** 
** Created by: Qt User Interface Compiler version 5.0.2 
** 
** WARNING! All changes made in this file will be lost when recompiling UI file! 
********************************************************************************/ 

#ifndef UI_CANYYEFFECTCONTROL_H 
#define UI_CANYYEFFECTCONTROL_H 

#include <QtCore/QVariant> 
#include <QtWidgets/QAction> 
#include <QtWidgets/QApplication> 
#include <QtWidgets/QButtonGroup> 
#include <QtWidgets/QCheckBox> 
#include <QtWidgets/QGridLayout> 
#include <QtWidgets/QHeaderView> 
#include <QtWidgets/QLabel> 
#include <QtWidgets/QSlider> 
#include <QtWidgets/QSpinBox> 
#include <QtWidgets/QWidget> 

QT_BEGIN_NAMESPACE 

class Ui_canyyeffectcontrol 
{ 
public: 
    QGridLayout *gridLayout; 
    QSlider *Threshold2Slider; 
    QLabel *Threshold1Label; 
    QLabel *ApertureSizeLabel; 
    QLabel *Threshold2Label; 
    QSpinBox *Threshold1Spin; 
    QSpinBox *Threshold2Spin; 
    QSpinBox *ApertureSizeSpin; 
    QSlider *ApertureSizeSlider; 
    QSlider *Threshold1Slider; 
    QCheckBox *EL2GLabel; 

    void setupUi(QWidget *canyyeffectcontrol) 
    { 
     if (canyyeffectcontrol->objectName().isEmpty()) 
      canyyeffectcontrol->setObjectName(QStringLiteral("canyyeffectcontrol")); 
     canyyeffectcontrol->resize(432, 210); 
     canyyeffectcontrol->setMinimumSize(QSize(153, 119)); 
     canyyeffectcontrol->setMaximumSize(QSize(432, 210)); 
     gridLayout = new QGridLayout(canyyeffectcontrol); 
     gridLayout->setObjectName(QStringLiteral("gridLayout")); 
     Threshold2Slider = new QSlider(canyyeffectcontrol); 
     Threshold2Slider->setObjectName(QStringLiteral("Threshold2Slider")); 
     Threshold2Slider->setOrientation(Qt::Horizontal); 

     gridLayout->addWidget(Threshold2Slider, 4, 1, 1, 2); 

     Threshold1Label = new QLabel(canyyeffectcontrol); 
     Threshold1Label->setObjectName(QStringLiteral("Threshold1Label")); 

     gridLayout->addWidget(Threshold1Label, 2, 0, 1, 1); 

     ApertureSizeLabel = new QLabel(canyyeffectcontrol); 
     ApertureSizeLabel->setObjectName(QStringLiteral("ApertureSizeLabel")); 

     gridLayout->addWidget(ApertureSizeLabel, 5, 0, 1, 1); 

     Threshold2Label = new QLabel(canyyeffectcontrol); 
     Threshold2Label->setObjectName(QStringLiteral("Threshold2Label")); 

     gridLayout->addWidget(Threshold2Label, 4, 0, 1, 1); 

     Threshold1Spin = new QSpinBox(canyyeffectcontrol); 
     Threshold1Spin->setObjectName(QStringLiteral("Threshold1Spin")); 

     gridLayout->addWidget(Threshold1Spin, 2, 3, 1, 1); 

     Threshold2Spin = new QSpinBox(canyyeffectcontrol); 
     Threshold2Spin->setObjectName(QStringLiteral("Threshold2Spin")); 

     gridLayout->addWidget(Threshold2Spin, 4, 3, 1, 1); 

     ApertureSizeSpin = new QSpinBox(canyyeffectcontrol); 
     ApertureSizeSpin->setObjectName(QStringLiteral("ApertureSizeSpin")); 

     gridLayout->addWidget(ApertureSizeSpin, 5, 3, 1, 1); 

     ApertureSizeSlider = new QSlider(canyyeffectcontrol); 
     ApertureSizeSlider->setObjectName(QStringLiteral("ApertureSizeSlider")); 
     ApertureSizeSlider->setOrientation(Qt::Horizontal); 

     gridLayout->addWidget(ApertureSizeSlider, 5, 1, 1, 2); 

     Threshold1Slider = new QSlider(canyyeffectcontrol); 
     Threshold1Slider->setObjectName(QStringLiteral("Threshold1Slider")); 
     Threshold1Slider->setOrientation(Qt::Horizontal); 

     gridLayout->addWidget(Threshold1Slider, 2, 1, 1, 1); 

     EL2GLabel = new QCheckBox(canyyeffectcontrol); 
     EL2GLabel->setObjectName(QStringLiteral("EL2GLabel")); 

     gridLayout->addWidget(EL2GLabel, 0, 0, 1, 1); 


     retranslateUi(canyyeffectcontrol); 

     QMetaObject::connectSlotsByName(canyyeffectcontrol); 
    } // setupUi 

    void retranslateUi(QWidget *canyyeffectcontrol) 
    { 
     canyyeffectcontrol->setWindowTitle(QApplication::translate("canyyeffectcontrol", "Canny effect control", 0)); 
     Threshold1Label->setText(QApplication::translate("canyyeffectcontrol", "Threshold size 1", 0)); 
     ApertureSizeLabel->setText(QApplication::translate("canyyeffectcontrol", "Aperture size", 0)); 
     Threshold2Label->setText(QApplication::translate("canyyeffectcontrol", "Threshold size 2", 0)); 
     EL2GLabel->setText(QApplication::translate("canyyeffectcontrol", "Enable L2G", 0)); 
    } // retranslateUi 

}; 

namespace Ui { 
    class canyyeffectcontrol: public Ui_canyyeffectcontrol {}; 
} // namespace Ui 

QT_END_NAMESPACE 

#endif // UI_CANYYEFFECTCONTROL_H 

इसका मतलब यह है कि मैं स्मृति (उदाहरण के लिए unique _ptr) जारी करने के लिए कोड को फिर से लिखने चाहिए और कोड इस

/******************************************************************************** 
** Form generated from reading UI file 'canyyeffectcontrol.ui' 
** 
** Created by: Qt User Interface Compiler version 5.0.2 
** 
** WARNING! All changes made in this file will be lost when recompiling UI file! 
** I modify the code 
********************************************************************************/ 

#ifndef UI_CANYYEFFECTCONTROL_H 
#define UI_CANYYEFFECTCONTROL_H 

#include <QtCore/QVariant> 
#include <QtWidgets/QAction> 
#include <QtWidgets/QApplication> 
#include <QtWidgets/QButtonGroup> 
#include <QtWidgets/QCheckBox> 
#include <QtWidgets/QGridLayout> 
#include <QtWidgets/QHeaderView> 
#include <QtWidgets/QLabel> 
#include <QtWidgets/QSlider> 
#include <QtWidgets/QSpinBox> 
#include <QtWidgets/QWidget> 

QT_BEGIN_NAMESPACE 

class Ui_canyyeffectcontrol 
{ 
public: 
    std::unique_ptr<QGridLayout> gridLayout; 
    std::unique_ptr<QSlider> Threshold2Slider; 
    std::unique_ptr<QLabel> Threshold1Label; 
    std::unique_ptr<QLabel> ApertureSizeLabel; 
    std::unique_ptr<QLabel> Threshold2Label; 
    std::unique_ptr<QSpinBox>Threshold1Spin; 
    std::unique_ptr<QSpinBox> Threshold2Spin; 
    std::unique_ptr<QSpinBox> ApertureSizeSpin; 
    std::unique_ptr<QSlider> ApertureSizeSlider; 
    std::unique_ptr<QSlider> Threshold1Slider; 
    std::unique_ptr<QCheckBox> EL2GLabel; 

    void setupUi(QWidget *canyyeffectcontrol) 
    { 
     if (canyyeffectcontrol->objectName().isEmpty()) 
      canyyeffectcontrol->setObjectName(QStringLiteral("canyyeffectcontrol")); 
     canyyeffectcontrol->resize(432, 210); 
     canyyeffectcontrol->setMinimumSize(QSize(153, 119)); 
     canyyeffectcontrol->setMaximumSize(QSize(432, 210)); 
     gridLayout = std::unique_ptr<QGridLayout> (new QGridLayout(canyyeffectcontrol)); 
     gridLayout->setObjectName(QStringLiteral("gridLayout")); 
     Threshold2Slider = std::unique_ptr<QSlider>(new QSlider(canyyeffectcontrol)); 
     Threshold2Slider.get()->setObjectName(QStringLiteral("Threshold2Slider")); 
     Threshold2Slider.get()->setOrientation(Qt::Horizontal); 

     gridLayout.get()->addWidget(Threshold2Slider.get(), 4, 1, 1, 2); 

     Threshold1Label = std::unique_ptr<QLabel> (new QLabel(canyyeffectcontrol)); 
     Threshold1Label.get()->setObjectName(QStringLiteral("Threshold1Label")); 

     gridLayout.get()->addWidget(Threshold1Label.get(), 2, 0, 1, 1); 

     ApertureSizeLabel = std::unique_ptr<QLabel> (new QLabel(canyyeffectcontrol)); 
     ApertureSizeLabel.get()->setObjectName(QStringLiteral("ApertureSizeLabel")); 

     gridLayout.get()->addWidget(ApertureSizeLabel.get(), 5, 0, 1, 1); 

     Threshold2Label = std::unique_ptr<QLabel> (new QLabel(canyyeffectcontrol)); 
     Threshold2Label.get()->setObjectName(QStringLiteral("Threshold2Label")); 

     gridLayout.get()->addWidget(Threshold2Label.get(), 4, 0, 1, 1); 

     Threshold1Spin = std::unique_ptr<QSpinBox> (new QSpinBox(canyyeffectcontrol)); 
     Threshold1Spin.get()->setObjectName(QStringLiteral("Threshold1Spin")); 

     gridLayout.get()->addWidget(Threshold1Spin.get(), 2, 3, 1, 1); 

     Threshold2Spin = std::unique_ptr<QSpinBox> (new QSpinBox(canyyeffectcontrol)); 
     Threshold2Spin.get()->setObjectName(QStringLiteral("Threshold2Spin")); 

     gridLayout->addWidget(Threshold2Spin.get(), 4, 3, 1, 1); 

     ApertureSizeSpin = std::unique_ptr<QSpinBox> (new QSpinBox(canyyeffectcontrol)); 
     ApertureSizeSpin.get()->setObjectName(QStringLiteral("ApertureSizeSpin")); 

     gridLayout.get()->addWidget(ApertureSizeSpin.get(), 5, 3, 1, 1); 

     ApertureSizeSlider =std::unique_ptr<QSlider> (new QSlider(canyyeffectcontrol)); 
     ApertureSizeSlider.get()->setObjectName(QStringLiteral("ApertureSizeSlider")); 
     ApertureSizeSlider.get()->setOrientation(Qt::Horizontal); 

     gridLayout->addWidget(ApertureSizeSlider.get(), 5, 1, 1, 2); 

     Threshold1Slider =std::unique_ptr<QSlider> (new QSlider(canyyeffectcontrol)); 
     Threshold1Slider.get()->setObjectName(QStringLiteral("Threshold1Slider")); 
     Threshold1Slider.get()->setOrientation(Qt::Horizontal); 

     gridLayout.get()->addWidget(Threshold1Slider.get(), 2, 1, 1, 1); 

     EL2GLabel = std::unique_ptr<QCheckBox> (new QCheckBox(canyyeffectcontrol)); 
     EL2GLabel.get()->setObjectName(QStringLiteral("EL2GLabel")); 

     gridLayout.get()->addWidget(EL2GLabel.get(), 0, 0, 1, 1); 


     retranslateUi(canyyeffectcontrol); 

     QMetaObject::connectSlotsByName(canyyeffectcontrol); 
    } // setupUi 

    void retranslateUi(QWidget *canyyeffectcontrol) 
    { 
     canyyeffectcontrol->setWindowTitle(QApplication::translate("canyyeffectcontrol", "Canny effect control", 0)); 
     Threshold1Label.get()->setText(QApplication::translate("canyyeffectcontrol", "Threshold size 1", 0)); 
     ApertureSizeLabel.get()->setText(QApplication::translate("canyyeffectcontrol", "Aperture size", 0)); 
     Threshold2Label.get()->setText(QApplication::translate("canyyeffectcontrol", "Threshold size 2", 0)); 
     EL2GLabel.get()->setText(QApplication::translate("canyyeffectcontrol", "Enable L2G", 0)); 
    } // retranslateUi 

}; 

namespace Ui { 
    class canyyeffectcontrol: public Ui_canyyeffectcontrol {}; 
} // namespace Ui 

QT_END_NAMESPACE 

#endif // UI_CANYYEFFECTCONTROL_H 
+0

क्या आप उस दीवार की दीवार को महत्वपूर्ण हिस्सों में ट्रिम कर सकते हैं? – arne

उत्तर

5

कैसे QObject व्युत्पन्न वर्ग स्मृति का प्रबंधन के बारे में पढ़ें की तरह होना चाहिए है - में संक्षेप में, यदि QObject माता-पिता के साथ बनाया गया है, तो माता-पिता नष्ट होने पर इसे नष्ट कर दिया जाएगा। आपके उदाहरण में, ऐसा लगता है कि सब कुछ canyyeffectcontrol के बच्चे के रूप में बनाया गया है, इसलिए जब वे ऑब्जेक्ट्स नष्ट हो जाएंगे।

0

क्यूटी ढांचा माता-पिता के संबंधों का एक पेड़ बनाता है। उदाहरण के लिए QSlider एस के लिए कन्स्ट्रक्टर तर्क माता-पिता है। माता-पिता के विनाश पर, सभी बच्चों को फिर से नष्ट कर दिया जाता है, इसलिए यदि आपके माता-पिता के रिश्ते सही हैं तो आपको कुछ भी साफ करने की आवश्यकता नहीं है।

यदि अभी भी स्मृति हानि है (वाल्ग्रिंड के साथ जांचें), यह एक क्यूटी बग हो सकता है या आपने रिश्तों को सही नहीं बनाया है।

3

नहीं! आपको क्यूटी की जेनरेट की गई फ़ाइलों को संशोधित नहीं करना चाहिए।

पहले कारण (फ़ाइल की बहुत शीर्षक में उत्पन्न):

चेतावनी! UI फ़ाइल को पुन: संकलित करते समय इस फ़ाइल में किए गए सभी परिवर्तन खो जाएंगे!

अपने संशोधनों इसका मतलब है कि हर बार जब आप भी अपने यूआई का सबसे नन्हा सा संशोधित खो जाएगा (जो अपने आप में एक भयानक समस्या है, हर यूआई परिवर्तन के साथ इसे फिर से समय और समय को संशोधित करने वाले)

दूसरा, क्यूटी अपने माता-पिता/बाल विगेट्स की एक तंत्र के साथ मेमोरी हैंडलिंग की देखभाल करने के साथ मेमोरी को अपने तरीके से संभालती है। आप इस here और here के बारे में पा सकते हैं।

जेनरेट की गई फ़ाइलों के लिए, आपको इसकी परवाह नहीं करनी चाहिए। फिर, अपनी फ़ाइल (उदाहरण के लिए कस्टम विजेट) के लिए, आपको delete का उपयोग नहीं करना चाहिए, लेकिन QObject::deleteLater()

संबंधित मुद्दे