这是从 qt ui 文件生成的代码,我看到代码使用 new 关键字分配内存但没有 delete类中用于删除已分配资源的关键字,这是 qt 开发人员的错误还是其他原因(没有释放资源)?
/********************************************************************************
** 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
最佳答案
阅读 QObject 派生类如何管理内存 - 简而言之,如果 QObject 是用父类构造的,那么当父类被销毁时它也会被销毁.在您的示例中,看起来所有内容都是作为 canyyeffectcontrol 的子项创建的,因此这些对象将在那时被销毁。
关于c++ - Qt UI Generator 不释放资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17853321/
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
我正在尝试将一个资源属性的默认值设置为另一个属性的值。我正在为我正在构建的tomcat说明书定义一个资源,其中包含以下定义。我想要可以独立设置的“名称”和“服务名称”属性。当未设置服务名称时,我希望它默认为为“名称”提供的任何内容。以下不符合我的预期:attribute:name,:kind_of=>String,:required=>true,:name_attribute=>trueattribute:service_name,:kind_of=>String,:default=>:name注意第二行末尾的“:default=>:name”。当我在Recipe的新block中引用我
我有一个数组数组,想将元素附加到子数组。+=做我想做的,但我想了解为什么push不做。我期望的行为(并与+=一起工作):b=Array.new(3,[])b[0]+=["apple"]b[1]+=["orange"]b[2]+=["frog"]b=>[["苹果"],["橙子"],["Frog"]]通过推送,我将推送的元素附加到每个子数组(为什么?):a=Array.new(3,[])a[0].push("apple")a[1].push("orange")a[2].push("frog")a=>[[“苹果”、“橙子”、“Frog”]、[“苹果”、“橙子”、“Frog”]、[“苹果”、“
有没有办法让Ruby能够做这样的事情?classPlane@moved=0@x=0defx+=(v)#thisiserror@x+=v@moved+=1enddefto_s"moved#{@moved}times,currentxis#{@x}"endendplane=Plane.newplane.x+=5plane.x+=10putsplane.to_s#moved2times,currentxis15 最佳答案 您不能在Ruby中覆盖复合赋值运算符。任务在内部处理。您应该覆盖+,而不是+=。plane.a+=b与plane.a=
出于某种原因,heroku尝试要求dm-sqlite-adapter,即使它应该在这里使用Postgres。请注意,这发生在我打开任何URL时-而不是在gitpush本身期间。我构建了一个默认的Facebook应用程序。gem文件:source:gemcuttergem"foreman"gem"sinatra"gem"mogli"gem"json"gem"httparty"gem"thin"gem"data_mapper"gem"heroku"group:productiondogem"pg"gem"dm-postgres-adapter"endgroup:development,:t
我是Ruby和这个网站的新手。下面两个函数是不同的,一个在函数外修改变量,一个不修改。defm1(x)x我想确保我理解正确-当调用m1时,对str的引用被复制并传递给将其视为x的函数。运算符当调用m2时,对str的引用被复制并传递给将其视为x的函数。运算符+创建一个新字符串,赋值x=x+"4"只是将x重定向到新字符串,而原始str变量保持不变。对吧?谢谢 最佳答案 String#+::str+other_str→new_strConcatenation—ReturnsanewStringcontainingother_strconc