Comparing QString causes the program to crash .
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:
Code:
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 ...
Re: Comparing QString causes the program to crash .
I have a feeling it might not have to do with the QString.
Are you using an uninitialised pointer?
Re: Comparing QString causes the program to crash .
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
Code:
#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:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
private slots:
void on_login_clicked();
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *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 ?
Re: Comparing QString causes the program to crash .
I guess it should be
But that does not explain why it crashed. It shouldn't even compile.
2 Attachment(s)
Re: Comparing QString causes the program to crash .
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
Re: Comparing QString causes the program to crash .
That's an error completely unrelated to the code you posted.
Re: Comparing QString causes the program to crash .
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).
Re: Comparing QString causes the program to crash .
Quote:
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 .
Re: Comparing QString causes the program to crash .
Quote:
Originally Posted by
ladiesfinger
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.
Re: Comparing QString causes the program to crash .
Thank u all guys for ur instant help:) especially tbscope .