Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QInputDialog causing a seg fault
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QInputDialog causing a seg fault

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    graham1941
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        graham1941
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What does a run through the debugger tell you ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            graham1941
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Got any threading involved ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved