PDA

View Full Version : Program crashes on creating new dialog



eekhoorn12
11th June 2009, 00:59
Hi,

I have a program in which i create a new dialog. It doesn't happen every time i create that dialog, but when i close the dialog and create it again after enough attempts the program crashes.

I create the dialog from a mainwindow with the following code


void MainWindow::newServer()
{
serverScreen = new newServerScreen();
serverScreen->setParent(this);
serverScreen->setWindowFlags(Qt::Window);
serverScreen->setAttribute(Qt::WA_DeleteOnClose);
serverScreen->setAttribute(Qt::WA_ShowModal);
serverScreen->show();
}

the code of the dialog is as follows
newServerScreen.h:

#ifndef NEWSERVERSCREEN_H
#define NEWSERVERSCREEN_H

#include <QDialog>
#include <QLineEdit>
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>

#include <server.h>

class newServerScreen : public QDialog
{
public:
newServerScreen();

//Widgets
QLineEdit *Addres;
QLineEdit *Nickname;
QLineEdit *Username;
QLineEdit *Password;
QCheckBox *UseSsl;
QCheckBox *RequireLogin;
QComboBox *Connections;

QLabel *labelAddres;
QLabel *labelNickname;
QLabel *labelUsername;
QLabel *labelPassword;
QLabel *labelConnections;

private:
void createInterface();
void createActions();

Server *newServer;
};

#endif // NEWSERVERSCREEN_H

newServerScreen.cpp:

#include "newserverscreen.h"

newServerScreen::newServerScreen()
{
this->createActions();
this->createInterface();
}

void newServerScreen::createActions()
{
}

void newServerScreen::createInterface()
{
this->setWindowTitle(tr("Add new server"));
Addres = new QLineEdit();
Nickname = new QLineEdit();
Username = new QLineEdit();
Password = new QLineEdit();
UseSsl = new QCheckBox();
RequireLogin = new QCheckBox();
Connections = new QComboBox();
labelAddres = new QLabel();
labelNickname = new QLabel();
labelUsername = new QLabel();
labelPassword = new QLabel();
labelConnections = new QLabel();
}


When i comment out all the lines with new in them in the newServerScreen.cpp file the program doesn't crash.

Once i got the following output from the program in QtCreator:

Starting O:/projects/Post_Program/debug/Post_Program.exe...
ASSERT: "r->d_func()->postedEvents >= 0" in file kernel\qcoreapplication.cpp, line 1235
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
QMutex::lock: Deadlock detected in thread 8976

I don't know what i did different that time because i can't replicate it.

I program in QtCreator 1.1.0 with Qt 4.5.1 on a Windows 7 RC 64bit


Thanks in advance

nish
11th June 2009, 02:39
try to give parent as "this"


void newServerScreen::createInterface()
{
this->setWindowTitle(tr("Add new server"));
Addres = new QLineEdit(this);
Nickname = new QLineEdit(this);
Username = new QLineEdit(this);
...
...
...
}

or insert them in a layout and set the layout on the dialog

eekhoorn12
11th June 2009, 12:52
Thanks that solved the problem.