Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED] How would I go about accessing Ui from another function in a different source file?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How would I go about accessing Ui from another function in a different source file?

Scheduled Pinned Locked Moved C++ Gurus
7 Posts 3 Posters 3.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.
  • M Offline
    M Offline
    maplesyrup23
    wrote on last edited by
    #1

    For example: in this chunk of code:

    SOLVED by using simple Signals and Slots implementation. See below.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on last edited by
      #2

      Try @setPlainText ( const QString & text )@


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        If your tCamera class is separate from the class which contains the Ui, then create a signal in your tCamera class which emits the QString you want to display. In your UI class, create a slot which receives a QString and sets the TextBrowser's text with that screen. Then somewhere outside of both classes, connect that signal to that slot.

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maplesyrup23
          wrote on last edited by
          #4

          Thanks mlong. I really appreciate your input on my other threads as well.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            My pleasure! I hope this helps. If so, please edit your first post and add [Solved] to the title. Thanks!

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maplesyrup23
              wrote on last edited by
              #6

              [quote author="mlong" date="1336501102"]If your tCamera class is separate from the class which contains the Ui, then create a signal in your tCamera class which emits the QString you want to display. In your UI class, create a slot which receives a QString and sets the TextBrowser's text with that screen. Then somewhere outside of both classes, connect that signal to that slot.

              [/quote]

              I've to clarify something about creating the signal. So you how would I create a signal emitting the string? Would it just be something like void sendSignal ("This is a string") ? I suppose if it is implemented this way, the connect function would make "This is a string" a parameter to the slot function, but I was just wondering how a void function with a parameter could transfer information in that way (If I am not misunderstanding anything)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                You don't know much about signals and slots, do you? ;) Knowing that stuff is probably one of the most important things you'll need to know to do any substantive work with Qt. I'd insist upon you going through the "documentation":/doc/qt-4.8/signalsandslots.html that covers it. (It's stuff you have to know cold.)

                But, in short (though I'm reluctant to spoon feed it...)

                you would define a signal such as:
                @
                signals:
                void mySignal(QString);
                @
                (you don't have to write the implementation of this. It will be autogenerated.)

                and to use it in your code you use:
                @
                emit mySignal("Whatever text I want to send.");
                @

                That signal would ideally be connected to a slot with a compatible signature:
                @
                connect(sourcePointer, SIGNAL(mySignal(QString)),
                destPointer, SLOT(someSlot(QString)));
                @

                Edit to add:

                Since the code for the body of the signal is generated by MOC, the return type of the signal is void. The string you want to pass in is a parameter because the MOC-generated code knows how to take that value passed in as a parameter and poke it into the corresponding parameter in the connected slot.

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                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