Hello,
I am new to QT and relatively new to c++.
I am trying to write a widget wich displays a number of QLineEdits in a grid layout.
The numberof cells and the aspect ratio are the arguments of the constructor.
Here's what I've written:
!------------------------------------------------------------------------------------------------
#ifndef TEXT_NETVIEWER_H
#define TEXT_NETVIEWER_H
#include <QWidget.h>
#include "QLineEdit.h"
class text_netviewer : public QWidget
{
public:
text_netviewer(int in, int num,QWidget *p=0);
QLineEdit *field;
virtual ~text_netviewer();
protected:
private:
};
#endif // TEXT_NETVIEWER_H
!-------------------------------------------------------------------------------------------------
#include "text_netviewer.h"
#include <cmath>
#include <iostream>
#include "QGridLayout.h"
using namespace std;
text_netviewer::text_netviewer(int in, int n,QWidget *p)
:QWidget(p)
{
int rows=int(ceil(double(n)/double(in)));
QGridLayout *grid=new QGridLayout(this);
field=new QLineEdit[rows*in];
int c=0;
for(int i=rows;i>0;--i)
{
for(int j=0;j<in;j++)
{
grid->addWidget(&field
|
C/C++ 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
|
,i,j);<br />
c++;<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
text_netviewer::~text_netviewer()<br />
{<br />
//dtor<br />
}<br />
!-------------------------------------------------------------------------------------------------<br />
<br />
This seems to work fine at first. It compiles with no complaints and shows the expected behaviour when run. <br />
When the window is closed however, Windows returns a "the program encountered an error and had to be closed. send error report?" message.<br />
<br />
I use QT 4.3.4 on XP(SP2) with mingw.<br />
<br />
I have no clue why this is. I am beginning to think that I am doing something fundamentally wrong, but can't see what.<br />
<br />
Any help appreciated.<br />
<br />
thans,<br />
<br />
t.
|