PDA

View Full Version : confused about QFileDialog in debug and release mode



furskytl
22nd December 2011, 16:20
I want to get file names in the function void QQTScene::dropEvent(QGraphicsSceneDragDropEvent *event),QQTScene is a class inherited from QGraphicsScene .Within the function,I write
fileName = QFileDialog::getOpenFileName(NULL, tr("打开图片"), "",tr("Image Files (*.png *.jpg *.bmp)"));
to get a file name.
However,this works perfectly in release mode,while in debug mode it crashes saying that the memory can't be "read".
What is wrong?Thanks!

Spitfire
22nd December 2011, 16:47
You're accessing some invalid pointer?

Where exacly does it crash, before getting the name, after, in getOpenFileName().
Use debugger to pin-point offending line.

furskytl
23rd December 2011, 11:10
Now if I just declare a QFileDialog variable in the function dropEvent() (just add one sentence),it will crash.If not adding this,it works perfectly.What's more,even in the release mode,it also craches after I just set the icon size of the toolbar.Is that strange?

Spitfire
23rd December 2011, 11:39
I don't know.

Can you paste some actual code, it's difficult to spot any problems when just working with my imagination.

furskytl
23rd December 2011, 12:01
void QQTScene::dropEvent(QGraphicsSceneDragDropEvent *event)
{
const QMimeData *mimeData = event->mimeData();
QString text = mimeData->text();

QGraphicsItem *item;

if(text == tr("文本"))
{
item = new QQTText(text);
connect(qgraphicsitem_cast<QQTText *>(item), SIGNAL(selectedChange(QGraphicsItem*)), this, SIGNAL(itemSelected(QGraphicsItem*)));
}
else if(text == tr("图像"))
{
QString fileName;
fileName = QFileDialog::getOpenFileName(0, tr("打开图片"), "",
tr("Image Files (*.png *.jpg *.bmp)"));

if(!fileName.isEmpty()){
QPixmap pixmap(fileName);
item = new QQTImage(pixmap);
QRectF r = item->boundingRect();
if(r.width() > 800)
{
item->scale(0.5, 0.5);
}
//connect(qgraphicsitem_cast<QQTImage *>(item), SIGNAL(resize()), this, SLOT(resize()));
/* ä¿®æ”¹å½“å‰å·¥ä½œç›®å½ •ï¼Œä½¿ä¸‹æ¬¡æ‰“开图 片的时候可以减 °‘重新选择目录 š„操作 */
QDir::setCurrent(QFileInfo(fileName).absolutePath( ));
}
else
{
event->setDropAction(Qt::IgnoreAction);
return;
}
}
item->setPos(event->scenePos());
addItem(item);

event->setDropAction(Qt::CopyAction);
event->accept();
}

It crashes at
fileName = QFileDialog::getOpenFileName(0, tr("打开图片"), "",
tr("Image Files (*.png *.jpg *.bmp)"));

I debug it to find that it crashes in system function
void qt_blend_argb32_on_argb32_sse2(uchar *destPixels, int dbpl,
const uchar *srcPixels, int sbpl,
int w, int h,
int const_alpha)
at line
BLEND_SOURCE_OVER_ARGB32_SSE2(dst, src, w, nullVector, half, one, colorMask, alphaMask);