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. Writing to form fields from other files than mainwindow.h

Writing to form fields from other files than mainwindow.h

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 227 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.
  • U Offline
    U Offline
    Uberlinc
    wrote on last edited by
    #1

    Hi,

    I'm trying to populating some form fields.
    If I reference them from mainwindow.cpp (which includes "ui.mailwindow.h") it can see them fine and works okay.

    I wish to reference them from another file of my own creation.
    I've added #include "ui_mainwindow.h" and #include "mainwindow.h" but it totally fails to recognise them.

    Can someone tell me where I'm going wrong here?

    Thanks.

    JonBJ 1 Reply Last reply
    0
    • U Uberlinc

      Hi,

      I'm trying to populating some form fields.
      If I reference them from mainwindow.cpp (which includes "ui.mailwindow.h") it can see them fine and works okay.

      I wish to reference them from another file of my own creation.
      I've added #include "ui_mainwindow.h" and #include "mainwindow.h" but it totally fails to recognise them.

      Can someone tell me where I'm going wrong here?

      Thanks.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Uberlinc
      You are trying to doing the wrong thing, and in the wrong way :)

      • Never #include ui_....h file into any file other than the .cpp of the same name. Regard it as a "private" include for that file only.

      • If you do want to access another class/form, #include "thatclass.h" only. You must then go into thatclass.{cpp,h} and export whatever you need to access explicitly, by writing appropriate public methods to access just what is needed from there.

      • However, you should never do that in the case of mainwindow. No other class/form should know about, or need to know about, anything in your main window. Indeed, other classes/forms should not even know or care whether there is any main window. Main window can know about the forms/classes it uses, but not the other way round. So why would you want or need to in your situation? If you do need to communicate, use signals/slots for this purpose.

      Thing of it like parents & children in real life. Parents can manipulate and instruct children what to do directly, if necessary. But children aren't allowed to do that to their parents; at best they can send little message-signals, which their parents can pick up and act on or ignore. At least that's what the relationship should look like. :D

      1 Reply Last reply
      1
      • U Offline
        U Offline
        Uberlinc
        wrote on last edited by
        #3

        Okay, so basically all manipulations of the form are done within the file.cpp/class to which it pertains?

        Thanks.
        I'll give it a try from that way.

        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