QT小程序,占用内存好大

yeelone 2010-04-17 12:57:38
我写了一个QT小程序,可是占用内存居然到17M。太恐怖了。
QT就这样子吗?还是有什么好办法可以减小内存的开销。
...全文
1198 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
crjwlaq 2011-06-19
  • 打赏
  • 举报
回复
用release版本的 不带调试信息的
blueice12 2010-04-23
  • 打赏
  • 举报
回复
很正常啊,QT的dll库比较大,所以就算最简单的程序也要占用十几兆内存。
yudongx 2010-04-19
  • 打赏
  • 举报
回复
linux下确实占用的内存很多,但是其他环境应该不会太多吧
  • 打赏
  • 举报
回复
这个没注意过....可能是LZ包含的库太多了吧
MicroSky2813 2010-04-17
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 yeelone 的回复:]
在linux下占用内存4M,在win下占用内存17M。
系统跟系统之间有这样的差别。
[/Quote]
两个系统的dll do实现是不一样的,所以会有差别的
yeelone 2010-04-17
  • 打赏
  • 举报
回复
在linux下占用内存4M,在win下占用内存17M。
系统跟系统之间有这样的差别。
MicroSky2813 2010-04-17
  • 打赏
  • 举报
回复
如果QGui 和 QCore的release版的dll有10+M,程序跑起来占内存10+M很正常,但是多了的话,应该使用的是同一个dll,那样内存占用就小了

PS:debug版的上百M
yeelone 2010-04-17
  • 打赏
  • 举报
回复
我把代码贴上来,大家帮我看看。怎么不能上传附件啊?
下面是main.cpp


#include "myrand.h"
#include <QtGui>


int main(int argc,char **argv)
{
QApplication app(argc,argv);
SELECT_NUM select;
select.show();


return app.exec();
}

下面是实现文件myqrand.cpp
#include "myrand.h"
#include <QApplication>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QTime>
#include <QComboBox>

// SELECT_NUM *se=new SELECT_NUM;

SELECT_NUM::SELECT_NUM(QWidget *parent)
:QDialog(parent)
{
//QMessageBox::warning(this,tr("spereadaflkjadf"),tr("dsfasd"),QMessageBox::Yes | QMessageBox::No);


//se->continueGetNumber=true;
continueGetNumber=true;

QVBoxLayout *vlayout2=new QVBoxLayout;

QHBoxLayout *hlayout=new QHBoxLayout;

QComboBox *combo=new QComboBox;

//lee line = new QTextEdit;
line = new QLineEdit;

//lee QPushButton *buttonstop=new QPushButton;
//lee QPushButton *buttongrip=new QPushButton;

buttonstop=new QPushButton;
buttongrip=new QPushButton;

combo->insertItem(0,"class 1");
combo->insertItem(1,"class 2");
buttonstop->setText(tr("stop"));
buttongrip->setText(tr("start"));

hlayout->addWidget(buttonstop);
hlayout->addWidget(buttongrip);
hlayout->addWidget(combo);
vlayout2->addWidget(line);
vlayout2->addLayout(hlayout);

setLayout(vlayout2);
setWindowTitle(tr("start to select the student"));

connect(buttonstop,SIGNAL(clicked()),this,SLOT(stopselect()));
connect(buttongrip,SIGNAL(clicked()),this,SLOT(startselect()));
connect(combo,SIGNAL(currentIndexChanged(int)),this,SLOT(set(combo->currentIndex())));
}

void SELECT_NUM::stopselect()
{

//se->continueGetNumber=false;
continueGetNumber=false;
}
void SELECT_NUM::startselect()
{
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
int n ;
int peo=0;

QString number="a";
if(index==0)
peo=54;
else
peo=64;

while(1)
{

n = (qrand()%peo);
line->setText(QString::number(n));
QApplication::processEvents ();
//lee if(!se->continueGetNumber)
if(!continueGetNumber)
break ;
}
//

}

void SELECT_NUM::set(int a)
{
index=a;
}


下面是头文件,myqrand.h
#ifndef QRAND_H
#define QRAND_H


#include <QtGui>
#include <QMainWindow>


QT_FORWARD_DECLARE_CLASS(QTextEdit)
QT_FORWARD_DECLARE_CLASS(QTextCharFormat)

class SELECT_NUM:public QDialog
{
Q_OBJECT

public:
SELECT_NUM(QWidget *parent=0);

private slots:
void stopselect();
void startselect();
void set(int a );


private:
//lee QVBoxLayout *vlayout;
//lee QHBoxLayout *hlayout;
//lee QGridLayout *glayout;
QLineEdit *line;
QPushButton *buttongrip,*buttonstop,*button2,*button1;


int index;
bool continueGetNumber;
};


#endif // QRAND_H

chenzhp 2010-04-17
  • 打赏
  • 举报
回复
人们都在说很大。。
kongyanmin 2010-04-17
  • 打赏
  • 举报
回复
太夸张了
bsr2009 2010-04-17
  • 打赏
  • 举报
回复
是不是加载太多东西了? 还有内存使用情况,建议检查一下程序。

16,223

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧