You are not logged in.

1

Wednesday, May 23rd 2012, 10:21am

New window by clicking

Hello everyone,

I got a problem using Qt, i want to create another window when i click on a push button. And in this window i want to display images. Here is the code i use :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
QWidget * centralWidget= new QWidget(mw_WatchPhotos);
		mw_WatchPhotos->resize(800,600);
		QGridLayout * layout = new QGridLayout();
		centralWidget->setLayout(layout);

		int size = 0;
		int u = 1;
		while ( size == 0 )
		{
			if(myClass->number_of_photos <= u*u) size = u;
			else u++;
		}
	
		QLabel * images = new QLabel[myClass->number_of_photos];

		int row = 0;
		for(int i = 0 ; i < myClass->number_of_photos ; ++i)
		{
			if(i%size == 0 && i != 0) row++;
			QPixmap myimage(QString(myClass->loadphotos_directory.c_str())+QString('/')+QString(myClass->files_name[i].c_str()));
			images[i].setPixmap(myimage.scaled(800/size,600/size));
			layout->addWidget(&images[i],row,i%size);
		}

		mw_WatchPhotos->setCentralWidget(centralWidget);
		mw_WatchPhotos->show();


In the code "mw_WatchPhotos" is a QMainWindow object declared in the class members.
The problem is when i launch that. The first time I click on the button the images are displayed correctly. But if I close the window and click again then images are going to display but just after i have an error :
"Debug Assertion Failed !"
The entire message of the error is in the attachment (Screenshot of the error).

Do you know why it does that ?
Thank you for your help,

Vincent.
VincentT has attached the following file:
  • qtError.png (15.13 kB - 9 times downloaded - latest: May 29th 2012, 4:27pm)

2

Wednesday, May 23rd 2012, 12:40pm

use your debugger. Probably has something to do with you using operator new[], which there is no need for. look at all of your new/deletes and where you directly index those raw arrays.


show the call stack will also help.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Thursday, May 24th 2012, 11:34am

Hello,

Thank for your answer i'm going to try remove the "new" then :).

Cheers,

Vincent

4

Thursday, May 24th 2012, 12:35pm

errr..., No! don't just make random changes!
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar threads