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. Accesing mainWindow variable in a Dialog Window
Qt 6.11 is out! See what's new in the release blog

Accesing mainWindow variable in a Dialog Window

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 3.9k 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.
  • T Offline
    T Offline
    tanny007
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

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

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

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

          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.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Klondike6
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              veeraps
              wrote on last edited by
              #6

              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

              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