[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


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


    #endif // TRACKRANGES_H@

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


    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

    HEADERS +=

    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();

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

  • Lifetime Qt Champion



    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<<"] "

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

  • 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

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