Results 1 to 2 of 2

Thread: Application crashes

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Application crashes

    I know I'm doing something wrong here, but I can't see it.
    The following application crashes on the line commented when it tries to put the value received from the query into the dialog form.
    No crash if I comment that line out.
    Can anyone please tell me what I have wrong?

    Qt Code:
    1. #include "makeStnDB.h"
    2. #include <iostream>
    3. #include <QString>
    4. #include <QtSql>
    5. #include "stninfodialog.h"
    6. #include <QDialog>
    7. #include <QtGui>
    8.  
    9. #include "ui_stninfodialog.h"
    10.  
    11. #include <QDebug>
    12.  
    13.  
    14. bool makeStnDB() {
    15. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    16. db.setDatabaseName("StnInfo.sqlite");
    17. db.open();
    18.  
    19. QSqlQuery query;
    20. query.exec("CREATE table stnInfo(id int primary key,call varchar(8),name varchar(80), "
    21. "address1 varchar(80),address2 varchar(80),city varchar(80),state varchar(80), "
    22. "postalCode varchar(20),country varchar(40),grid varchar(8), "
    23. "cqZone varchar(8),ituZone varchar(8),latitude varchar(8), "
    24. "longitude varchar(8),licenseClass varchar(12))");
    25.  
    26. //Check to see if stninfo exists...
    27. query.exec("SELECT call, name, address1, address2, city, state, postalCode, country, grid, cqZone, ituZone, latitude, longitude, licenseClass FROM stnInfo");
    28.  
    29. StnInfoDialog *StnInfoD = new StnInfoDialog();
    30.  
    31. Ui_StnInfoDialog *stn = new Ui_StnInfoDialog();
    32.  
    33. if (!query.next()) {
    34. // show the entry form if record not exists
    35. StnInfoD->exec();
    36. StnInfoD->raise();
    37. // need to insert data on 'ok' click
    38. } else {
    39. // if record exists retrieve the data and display it
    40. QString call = query.value(0).toString();
    41. qDebug() << call; // value ok in console
    42. stn -> call -> setText(call); // CRASHES ON THIS LINE
    43.  
    44. }
    45. return query.exec();
    46. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Application crashes

    Qt Code:
    1. QString call = query.value(0).toString();
    2. qDebug() << call; // value ok in console
    3. stn -> call -> setText(call); // CRASHES ON THIS LINE
    To copy to clipboard, switch view to plain text mode 

    If you are trying to access setText with -> then it means call from stn should be allocated on heap (with operator new). Now you are trying to access a call that doesn't exist.

    You didn't say anything about where you are trying to apply the call value. Is it some kind of new dialog with QLabel on it?
    Last edited by RSX; 2nd November 2009 at 10:35.

Similar Threads

  1. Phonon crashes application when creating a VideoPlayer
    By core2000 in forum Qt Programming
    Replies: 0
    Last Post: 29th September 2009, 08:58
  2. QtStyles and Application Crashes
    By vladozar in forum Qt Programming
    Replies: 0
    Last Post: 19th September 2009, 14:59
  3. My application crashes
    By sophister in forum Qt Programming
    Replies: 13
    Last Post: 27th April 2009, 07:39
  4. Replies: 1
    Last Post: 30th March 2009, 22:25
  5. Replies: 5
    Last Post: 27th May 2006, 13:44

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.