Accesing mainWindow variable in a Dialog Window



  • I am a newbie in qt and c++ and i took the input filename in the MainWindow,but i wanted to access the filename in the dialog Window as well . I am having problems in doing so.I have included the MainWindow header file.
    I tried using
    @ui->lineEdit->insert(parent->fileName);@

    But i get a error saying:
    Class QWidget has no member named fileName.
    So how can i access the fileName.?


  • Moderators

    Hi,

    I am wondering what filename you are referring to.
    Probably, the best is that you are posting the header and source file containing main window.



  • [quote author="koahnig" date="1334245644"]I am wondering what filename you are referring to.
    [/quote]
    So is the compiler, it seems :-)



  • Sorry, that was not really helpful.

    I guess the problem is, that parent is of type QWidget*, not of the actual type of your mainWindow that does have the fileName member.



  • One way to share something with a dialog would be to pass it in as an argument to the constructor for the dialog. The dialog can then use the passed argument, rather than trying to reference an object in the main window.



  • bq. tanny007 wrote: i took the input filename in the MainWindow,but i wanted to access the filename in the dialog Window as well

    How did you get the file name? If it isn't a property of Parent (that too a public property), then I guess you might not access as you did
    @ui->lineEdit->insert(parent->fileName);@

    Easiest way would be to pass the file name to Dialog

    ~veeraps


Log in to reply
 

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