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. Erroneous this-Pointer in QFileDialog::getOpenFileName(this,...)
QtWS25 Last Chance

Erroneous this-Pointer in QFileDialog::getOpenFileName(this,...)

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.6k Views
  • 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.
  • M Offline
    M Offline
    mrtc3
    wrote on last edited by
    #1

    Hello people,

    I have a XML_Parser class which is defined as following

    @class XML_Parser : public QWidget
    {
    Q_OBJECT
    public:
    XML_Parser(QWidget*, Client*);
    //..
    };
    @

    and its corresponding sourcefile...

    @
    XML_Parser::XML_Parser(QWidget *parent, Client *t_client) : QWidget(parent) {}

    void XML_Parser::readXMLFile() {
    QString fileName = QFileDialog::getOpenFileName(this, tr("XML-File"), "C:\path", tr("XML-Files(*.xml)"));

    xml_File = new QFile(fileName);
    //..
    }@

    So when I instantiate a XML_Parser Object in the parent class:
    @if (!client) xml_PLR = new XML_Parser(this, client);@

    and back in the XML_Parser-Class I call readXMLFile():
    Here, the this-pointer in QFileDialog::getOpenFileName(this, tr("XML-File"), "C:\path", tr("XML-Files(*.xml)")); is erroneous, as you can see in the following screenshot (Breakpoint in qfiledialog_win.cpp)..

    http://img804.imageshack.us/img804/5152/thispointer.png

    What am I doing wrong?

    Cheers
    Murat

    There are 10 types. Those who understand binary and those who don't .)

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      Your image doesn't show for me.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrtc3
        wrote on last edited by
        #3

        Try: http://imageshack.us/photo/my-images/804/thispointer.png/ and then enlarge please.

        In qfiledialog_win.cpp:
        @QString qt_win_get_open_file_name(const QFileDialogArgs &args,
        QString *initialDirectory,
        QString *selectedFilter)@
        the args.parent is erroneous thus @modal_widget.setParent(args.parent, Qt::Window);@
        throws an error.

        Note: The parent derives from QObject, not QWidget!

        There are 10 types. Those who understand binary and those who don't .)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Is there a reason you do all your work in the constructor of your XML_Parser class? An issue might be that the class is not fully constructed yet at the moment you try to show your file dialog. At the very least, it is not shown yet.

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            This is odd, your usage of QFilaDialog is ok, as Andre pointed out it is probably an issue with the flow of your code.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrtc3
              wrote on last edited by
              #6

              [quote author="Andre" date="1330421623"]Is there a reason you do all your work in the constructor of your XML_Parser class?[/quote]

              What do you mean with all the work, exactly?
              The constructor sets two pointers: QWidget *parent and a Client *t_client , only.
              The readXMLFile method is called later..

              There are 10 types. Those who understand binary and those who don't .)

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Ah, sorry, I missed the new method start readXMLFile, I guess because you left it out of the header you showed. My bad. I did not read careful enough.

                Would you be able to create and share a minimal, yet complete and compilable example that shows this behaviour?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrtc3
                  wrote on last edited by
                  #8

                  [quote author="Andre" date="1330422338"]Ah, sorry, I missed the new method start readXMLFile, I guess because you left it out of the header you showed. My bad. I did not read careful enough.[/quote] Never mind!

                  [quote author="Andre" date="1330422338"]Would you be able to create and share a minimal, yet complete and compilable example that shows this behaviour? [/quote] I was keen to do that, but the minimal compilable example worked perfectly (no extrernal *.dll as described below).

                  On account of this, I have another guess: I have to use an external *.dll (no source available). When I start my application without that *.dll everything works fine, thus I'll contact the DLL-Vendor and post my results asap.

                  Anyway, If you can think of anything else, please drop me a line ;)

                  Thank you for your assistance.

                  Murat

                  There are 10 types. Those who understand binary and those who don't .)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    Do you happen to mix debug and release DLLs of Qt? If so, this cries for disaster... (different memory management modules and the like). It could also be the case if your external lib is built with a different Visual Studio version than your code.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    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