Results 1 to 10 of 10

Thread: Comparing QString causes the program to crash .

  1. #1
    Join Date
    Aug 2010
    Location
    Chennai
    Posts
    21
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy 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:
    Qt Code:
    1. void MainWindow::on_login_clicked()
    2. {
    3. user=usernameip->displayText(); // usernameip is lineedit's name
    4. pass=passwordip->displayText(); // '' ''
    5. if(user.compare("user")&&pass.compare("pass"))
    6. {
    7. //i wanted to invoke another dialog from here but i cant put even a msgbox
    8. //'coz the program crashes bfore entering this
    9. }
    To copy to clipboard, switch view to plain text mode 

    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 ...

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default 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?

  3. The following user says thank you to tbscope for this useful post:

    ladiesfinger (6th November 2010)

  4. #3
    Join Date
    Aug 2010
    Location
    Chennai
    Posts
    21
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation 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

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3. #include <QMainWindow>
    4. #include <QMessageBox>
    5. #include "ui_mainwindow.h"
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. class Ui_MainWindow;
    10. }
    11.  
    12. class MainWindow : public QMainWindow ,public Ui_MainWindow
    13. {
    14. Q_OBJECT
    15. public:
    16. QString user;
    17. QString pass;
    18. explicit MainWindow(QWidget *parent = 0);
    19. ~MainWindow();
    20. private:
    21. Ui::MainWindow *ui;
    22. private slots:
    23. void on_login_clicked();
    24. };
    25. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10. MainWindow::~MainWindow()
    11. {
    12. delete ui;
    13. }
    14. void MainWindow::on_login_clicked()
    15. {
    16. user=usernameip->displayText();
    17. pass=passwordip->displayText();
    18. if(user.compare("user")&&pass.compare("pass"))
    19. {
    20. //msg.setText("The username is correct");
    21. //msg.exec();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

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

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Comparing QString causes the program to crash .

    I guess it should be
    Qt Code:
    1. ui->usernameip
    To copy to clipboard, switch view to plain text mode 

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

  6. The following user says thank you to tbscope for this useful post:

    ladiesfinger (6th November 2010)

  7. #5
    Join Date
    Aug 2010
    Location
    Chennai
    Posts
    21
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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
    Attached Images Attached Images

  8. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Comparing QString causes the program to crash .

    That's an error completely unrelated to the code you posted.

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #8
    Join Date
    Aug 2010
    Location
    Chennai
    Posts
    21
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Comparing QString causes the program to crash .

    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 .

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Comparing QString causes the program to crash .

    Quote Originally Posted by ladiesfinger View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #10
    Join Date
    Aug 2010
    Location
    Chennai
    Posts
    21
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Comparing QString causes the program to crash .

    Thank u all guys for ur instant help especially tbscope .

Similar Threads

  1. How can I manage an unexpected program crash?
    By cydside in forum Qt Programming
    Replies: 1
    Last Post: 22nd August 2009, 06:59
  2. Program Crash
    By jonmatteo in forum Qt Programming
    Replies: 5
    Last Post: 17th June 2009, 14:47
  3. Program crash when a signal is emitted
    By croscato in forum Qt Programming
    Replies: 7
    Last Post: 22nd November 2008, 22:24
  4. Program crash
    By Pragya in forum Qt Programming
    Replies: 7
    Last Post: 29th June 2007, 07:37
  5. Crash on QString Destructor
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 14:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.