PDA

View Full Version : Comparing QString causes the program to crash .



ladiesfinger
5th November 2010, 15:18
Hi all ,
i designed a form using Qt designer and compiled it with uic to produce
ui_mainwindow.h
The other files are :
1. main.cpp
2. mainwindow.cpp
3. mainwindow.ui
4. mainwindow.h ( default files )

i've included ui_mainwindow file in header file.
In my form , among many other fields , i want to get username and password from QLineEdit .
When the user press login pushbutton , it should check the name and password manually entered in the corresponding slot invoked .
here's the slot's func:


void MainWindow::on_login_clicked()
{
user=usernameip->displayText(); // usernameip is lineedit's name
pass=passwordip->displayText(); // '' ''
if(user.compare("user")&&pass.compare("pass"))
{
//i wanted to invoke another dialog from here but i cant put even a msgbox
//'coz the program crashes bfore entering this
}


Both user and pass are declared as QString in header file.
If u need the code for other files , ill post it immediately .
i spent about some 3 hours without success , this is my first prog ...

tbscope
5th November 2010, 17:08
I have a feeling it might not have to do with the QString.
Are you using an uninitialised pointer?

ladiesfinger
6th November 2010, 03:31
tbscope , i checked that but i didn't initialise any of the UI items manually.i left what uic generated . Is that necessary to initialise them ?

here's the code ....they're simple .
mainwindow.h



#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QMessageBox>
#include "ui_mainwindow.h"

namespace Ui {
class MainWindow;
class Ui_MainWindow;
}

class MainWindow : public QMainWindow ,public Ui_MainWindow
{
Q_OBJECT
public:
QString user;
QString pass;
QMessageBox msg;
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
private slots:
void on_login_clicked();
};
#endif // MAINWINDOW_H


mainwindow.cpp




#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_login_clicked()
{
user=usernameip->displayText();
pass=passwordip->displayText();
if(user.compare("user")&&pass.compare("pass"))
{
//msg.setText("The username is correct");
//msg.exec();
}
}


And the uic generated file ui_mainwindow.h file
Does anyone has idea wat's wrong ?

tbscope
6th November 2010, 05:22
I guess it should be

ui->usernameip

But that does not explain why it crashed. It shouldn't even compile.

ladiesfinger
6th November 2010, 05:47
thnk u tbscope ,but i reallly didn't understand that.
The program compiled and ran.
Only wen i click the login button ,i says " windows app stopped working".
here's the screenshots as attachments .

The error statement :
Starting C:\Users\Administrator\Documents\Qt Pros\TravelBooking-build-desktop\debug\TravelBooking.exe...
Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

tbscope
6th November 2010, 08:34
That's an error completely unrelated to the code you posted.

wysota
6th November 2010, 08:50
As a side note (completely unrelated to the problem) - I think you are not using "layouts" in your code which makes your GUI look and act really bad (sorry for being blunt).

ladiesfinger
6th November 2010, 09:24
That's an error completely unrelated to the code you posted
tbscope , I've posted all the files ! . I think i should write a new one step by step carefully.

hi wysota , you mean i've to write the code without the help of designer ?
Does designing & then using uic tool is a bad advice ? I thought writing manually will take lots of time .

wysota
6th November 2010, 12:17
hi wysota , you mean i've to write the code without the help of designer ?
No. I mean you need to organize widgets in layouts. Also see conept of layouts in Designer docs.

ladiesfinger
6th November 2010, 17:17
Thank u all guys for ur instant help:) especially tbscope .