[SOLVED]QInputDialog causing a seg fault



  • Sirs
    I am having a problem with QInputDialog causing a segfault.
    Here is my header:-
    @#ifndef TRACKRANGES_H
    #define TRACKRANGES_H
    #include <QInputDialog>
    #include <QDialog>
    #include <QtGui>

    class trackRanges : public QDialog
    {
    Q_OBJECT

    public:
    trackRanges();

    QInputDialog dlg;
    QString ranges;
    
    void getRange(void);
    

    };

    #endif // TRACKRANGES_H@

    And the implementation:
    @#include "trackRanges.h"

    trackRanges::trackRanges(){}

    void trackRanges::getRange()
    {
    bool ok = true;
    ranges = dlg.getText(NULL,"Track Range","Input range",QLineEdit::Normal, "", &ok);
    }@

    The common pro file

    @#-------------------------------------------------

    Project created by QtCreator 2014-11-30T17:50:30

    #-------------------------------------------------

    QT += core

    QT -= gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = cdTracks
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app
    LIBS += -lutilities

    SOURCES += main.cpp
    cdFrameTimes.cpp
    trackRanges.cpp

    HEADERS +=
    cdTracks.h
    cdFrameTimes.h
    trackRanges.h@

    And the calling routine (stub):
    @void setUp()
    {
    QString cmd;
    QStringList args;
    bool ok;

    // QString ranges = QInputDialog::getText(NULL, "title", "label",QLineEdit::Normal, "", &ok);
    // dbug<<ranges;

    trackRanges *trks = new trackRanges();
    trks->getRange();
    dbug<<trks->ranges;@
    

    The commented out section in the stub also causes a segfault !!
    What am I doing wrong?
    Thank you in anticipation
    Graham


  • Lifetime Qt Champion

    Hi,

    @dlg.getText@

    This is wrong, getText is a static method so it's not the correct way to do it. Anyway that doesn't explain the crash.

    What is dbug ?

    What does a run through the debugger tell you ?
    What version of Qt/OS are you running ?



  • Thank you SGaist for your reply.
    OK I get that about dlg.getText but I also get a segfault at the commented out lines (7 and 8) in the stub. I think there must be something else going on. I will continue to investigate.
    dbug is a useful macro of mine set in a utilities header:

    @
    #include <QDebug>
    #ifndef dbug
    #define dbug qDebug()<<"["<<FUNCTION<<"; "<<LINE<<"] "
    #endif
    @

    I'm using Qt5 on Linux mint16.
    Thank you again
    Regards
    Graham


  • Lifetime Qt Champion

    What does a run through the debugger tell you ?



  • Hi SGaist
    The dbugger showed a segfault at line 10 in the stub section.
    i tried to write a input dialogue of my own. That failed as well ! The problem is much deeper. I am in the process of starting the whole program from scratch.
    Thank you for your advice and help.
    Kind regards
    Graham.


  • Lifetime Qt Champion

    Got any threading involved ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.