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. Newbie Question - Form design or Code?

Newbie Question - Form design or Code?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 5 Posters 1.7k 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.
  • U Offline
    U Offline
    Uberlinc
    wrote on last edited by
    #1

    Hi,

    Just starting out with Qt and using Qt Creator 4.4.1 (Based on Qt 5.9)
    I'm a little fuzzy on the whole "create in forms/create in code" topic.

    So, if I create an object (e.g. button, tickbox, slider etc) in code, it appears, but if I create said object in the form editor, it doesn't create any corresponding code to account for this?
    e.g. If I create a slider and a progress bar, I can link the two graphically, but there will be no line of code connecting the signal to the slot?
    Is this correct?

    If I then go and create something in code, does this play well with the objects created graphically?
    Does this mean that, during debug, you must remember what was created on the form and what was created in code so change the details there?

    I was watching the videos by VoidRealms on YouTube.
    I could have sworn that he created something graphically and then went to change the code that had been magically created as a result of the object that he created.
    Am I mistaken?

    Is this a mode that you can switch on or off?

    Can anyone clear this up for me?

    Thanks,

    Uberlinc.

    jsulmJ 1 Reply Last reply
    0
    • U Uberlinc

      Hi,

      Just starting out with Qt and using Qt Creator 4.4.1 (Based on Qt 5.9)
      I'm a little fuzzy on the whole "create in forms/create in code" topic.

      So, if I create an object (e.g. button, tickbox, slider etc) in code, it appears, but if I create said object in the form editor, it doesn't create any corresponding code to account for this?
      e.g. If I create a slider and a progress bar, I can link the two graphically, but there will be no line of code connecting the signal to the slot?
      Is this correct?

      If I then go and create something in code, does this play well with the objects created graphically?
      Does this mean that, during debug, you must remember what was created on the form and what was created in code so change the details there?

      I was watching the videos by VoidRealms on YouTube.
      I could have sworn that he created something graphically and then went to change the code that had been magically created as a result of the object that he created.
      Am I mistaken?

      Is this a mode that you can switch on or off?

      Can anyone clear this up for me?

      Thanks,

      Uberlinc.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Uberlinc said in Newbie Question - Form design or Code?:

      it doesn't create any corresponding code

      It does. This is what moc tool is used for. No magic involved :-) Take a look at moc_* files in your build directory after building your project.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by SGaist
        #3

        Hi,

        Yes code is generated for you. When using designer you get a .ui file that is an XML describing the widgets you are going to use. That file will be processed by uic to generate the corresponding C++ code.

        There's no problem mixing designer created widgets with code create ones.

        No you don't, when debugging you'll be able to easily distinguish the debugger shows the variable names so you can easily spot which are yours and which comes from designer.

        Don't modify the code generated (moc_ or ui_ files), there are already warnings in them for that. These are generated at compilation time, so don't touch them.

        What mode are you thinking about ?

        [edit: Fixed wrong naming, thanks @aha_1980 SGaist]

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        aha_1980A 1 Reply Last reply
        2
        • SGaistS SGaist

          Hi,

          Yes code is generated for you. When using designer you get a .ui file that is an XML describing the widgets you are going to use. That file will be processed by uic to generate the corresponding C++ code.

          There's no problem mixing designer created widgets with code create ones.

          No you don't, when debugging you'll be able to easily distinguish the debugger shows the variable names so you can easily spot which are yours and which comes from designer.

          Don't modify the code generated (moc_ or ui_ files), there are already warnings in them for that. These are generated at compilation time, so don't touch them.

          What mode are you thinking about ?

          [edit: Fixed wrong naming, thanks @aha_1980 SGaist]

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I fully ack what @SGaist said, with the addition that the form files end in .ui and the generated files start with ui_

          the compiler is named uic, indeed.

          Qt has to stay free or it will die.

          1 Reply Last reply
          1
          • BuckwheatB Offline
            BuckwheatB Offline
            Buckwheat
            wrote on last edited by
            #5

            I am also in full agreeance with @SGaist!

            There is a neat little secret when using form designer and needing connections. You do not need to add signals/slots to the form. Just do the following:

            In header...
            void on_<objectName>_<signal name> (...);

            In source...
            void Class::on_<objectName>_<signal name> (...)
            {
            --- do stuff ---
            }

            This will automaticly pickup your object and connect the signal/slot. No fuss, no muss.

            For example:
            void on_button_clicked (bool checked);

            void Class:on_button_clicked (bool checked)
            {
            --- do something ---
            }
            .

            This is fun-with-designer 101!

            Dave Fileccia

            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