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



  • 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



  • Your image doesn't show for me.



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



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



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



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



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



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



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


Log in to reply
 

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