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. [solved] adding Qt to existing program

[solved] adding Qt to existing program

Scheduled Pinned Locked Moved General and Desktop
45 Posts 6 Posters 21.3k 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #25

    OK, thanks. So, if I:

    bring generator and widget files into my existing project

    take all my stuff out of my main and put it into generator

    replace my main with the one you posted

    do the refactor thingie

    Is that on the right track?

    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #26

      OK, I've changed my approach slightly. I decided to create a class to contain all the stuff for my main routine. I've called this class Soc, and its only data members are an object of another class (Filter), and some control variables.

      Now I'm having some trouble getting the Soc constructor right. The Soc constructor needs to pass an argument to the Filter constructor. The problem is, Soc (like generator) inherits its constructor from the QObject class. As such, it isn't prepared to take any additional parameters (like the argument I want to pass).

      How can I form the Soc constructor so that I can pass an argument to the Filter constructor? Or, is there a better way of doing this?

      Thanks.

      EDIT:

      I think I resolved this problem by adding the Filter initialization to the Soc parameter initialization (did I word that correctly?):

      @#include "Soc.h"
      const int resetValue = 55;

      using namespace std;

      Soc::Soc(QObject *parent) :
      QObject(parent), filter(resetValue)
      {
      }
      @

      Now, I'm getting a symbol not found error:

      bq. Undefined symbols:
      "Soc::getCoeffs(int*, int*)", referenced from:
      Soc::runOneCycle() in Soc.o
      Soc::qt_metacall(QMetaObject::Call, int, void**)in moc_Soc.o
      ld: symbol(s) not found
      collect2: ld returned 1 exit status

      Is this somehow related to the fact that the calling routine (I've named it Soc::runOneCycle()) is defined as a public slot, and not an "ordinary" member function?

      EDIT 2:

      Aargh. Please ignore previous lame question. My fault for trying to work too fast. I'll come back when I have something legit.

      1 Reply Last reply
      0
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #27

        OK...I've cleared the decks of my dumb mistakes (I think). I believe that I have now correctly implemented a class Soc, which contains a routine called runOneCycle() that replaces most of the functionality in my original main(). I now need to "hook it up" so it gets called. I guess the next step is to implement a version of the widget software that Zap posted above. Right now, I'd be happy if it ran 100 times, and showed the results of two variables after each running. (I have lots of plans for enhancing this, but this will do for now.)

        I won't need a timer (yet), so we can eliminate that part of the code. So...do I need just one connect statement? Or, do I need two, since I'm planning on displaying the values of two variables with the Soc class?

        Thanks...I think I'm slowly getting closer...

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #28

          Are you able to post your code? If yes then please do, if not then we'll have to work with examples still. Not a problem either way...

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #29

            I can post some extracts, which would hopefully be good enough. I removed some irrelevant stuff for brevity.

            Here's Soc.h:

            @#ifndef SOC_H
            #define SOC_H

            #include <QObject>
            #include <iostream>
            #include <fstream>
            #include <iomanip>
            #include "DemodShaperFilter.h"

            class Soc : public QObject
            {
            Q_OBJECT
            private:
            Filter filter; // Soc contains one filter for now.
            /*

            • clocks and resets.
              /
              bool clockEnable;
              bool clockState;
              // bool systemReset;
              bool filterReset;
              /
            • arguments to drive the filter processing.
              */

            int shaperCoeffI[NBR_CELLS];
            int shaperCoeffQ[NBR_CELLS];
            int combGainI;
            int combGainQ;
            int shaperOutI, shaperOutQ;

            public:
            explicit Soc(QObject *parent = 0);
            int getCoeffs(int *aI, int *aQ);

            signals:
            void dataChanged (double value);
            public slots:
            void runOneCycle();
            };
            #endif // SOC_H
            @

            And here's the .cpp file:

            @#include "Soc.h"
            const int resetValue = 55;

            //Soc::Soc(QObject *parent) :
            // QObject(parent)
            Soc::Soc(QObject *parent) :
            QObject(parent), filter(resetValue)
            {
            }

            void Soc::runOneCycle()
            {
            static int i=0;
            int rc;
            /*

            • test a single filter.
              */

            // temporarily use simple variables for comb stuff.

            combGainI = i;
            combGainQ = i*2;
            i++;

            systemClock.setClock(HIGH);
            filter.cycle(combGainI, // run the high cycle.
            shaperCoeffI,
            combGainQ,
            shaperCoeffQ,
            shaperOutI,
            shaperOutQ,
            clockEnable,
            filterReset);

            return;
            }
            @

            1 Reply Last reply
            0
            • mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #30

              So...I've added the widget files from the example above to my program, and changed m_generator to a Soc variable called (creatively enough) soc. The program runs, and produces the correct output (as displayed on the console), but I'm not getting anything in my GUI window.

              I believe I need to modify this line of code in widget.cpp:

              @ connect (soc, SIGNAL(dataChanged(double)), this, SLOT(setValue(double)));
              @

              I imagine I'd have to modify the doubles to ints, but...I need to tell it to look at my two variables. Do I:

              1. need two connect statements for this?
              2. replace "this" with soc.member-name?

              I guess I should also modify setValue to accept an int instead of a double, too.

              Thanks.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #31

                Thje connect is correct. But I fI look at your last code, where do you emit the signal?

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #32

                  Oops.

                  I guess I need a emit dataChanged() call, don't I?

                  So, my question now is...what do I put in as a parameter for this call? I guess this is the missing link to my understanding of how these signals work. (It also looks like I missed changing a double to int in the Soc.h file.)

                  Thanks.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #33

                    Hi,

                    you have to put a double in, as specified in the header.
                    Which one, I can't tell you, that's depending on your application.
                    Typically, the value you want to notify :-)

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #34

                      So, I use a double in the call even if the variable I want to display is an int? What exactly does that double represent: I thought it was the variable I wanted to display...

                      EDIT: I just put the dataChanged() call into my code, and it seems to work. Now, if I want to do this for two variables, what all do I have to duplicate? Obviously, I'll need two calls to dataChanged(), but what else do I have to do?

                      Thanks.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        giesbert
                        wrote on last edited by
                        #35

                        Think a bit, how the Qt widgets to it.

                        Look at QSpineBox:

                        • it has a signal valueChanged(int) and sends the changed value.

                        Look at QDoubleSpineBox:

                        • it has a signal valueChanged(double) and sends the changed value.

                        Look at QComboBox:

                        • void activated ( int index )
                        • void activated ( const QString & text )
                          both signals are emitted, with different content.

                        The client can connect to the signal he wants and has to interpret the values.

                        You can do a dataChanged() signal and leave it to the client to query all values and check which ones are changed, or do a dataChanged1() and dataChanged2() so the client knows, which value but has to query the new value. or you do

                        • dataChanged1(int)
                        • dataChanged2(int)
                          and deliver the new values to the client.

                        But I would rename dataChanged1(int) to some senseful names.

                        Nokia Certified Qt Specialist.
                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          ZapB
                          wrote on last edited by
                          #36

                          Which values are you trying to have displayed and what are their types? If you are emitting a single double then the signal, slot and connect are fine.

                          If you want to display 2 doubles then you need to modify:

                          • The dataChanged() signal to have two double arguments ie

                          @void dataChanged( double val1, double val2 );@

                          • The Widget::setValue() function to accept a corresponding pair of doubles:

                          @void setValue( double val1, double val2 );@

                          • The connect to use the new signal/slot signatures:

                          @connect (soc, SIGNAL(dataChanged(double,double)), this, SLOT(setValue(double,double)));@

                          Then finally you actually need to emit your signal from your calculation function.

                          If instead you are using int's then simply replace double for int in the above.

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

                          1 Reply Last reply
                          0
                          • mzimmersM Offline
                            mzimmersM Offline
                            mzimmers
                            wrote on last edited by
                            #37

                            Thanks for the explanation, Gerolf...that does help.

                            Zap: I wish to display two ints. I understand now that I have to replace the doubles with ints. Now that I'm displaying two variables (ints), what is the syntax for forming the output string? I tried this:
                            @ QString s = QString("shaperOutI is %1. shaperOutQ is %2.").arg(shaperOutI, shaperOutQ);
                            @
                            But that gives no output at all. Do I need two separate strings? What if I wanted the output on separate lines?

                            Thanks. I'll have some more questions when I finish waking up.

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              giesbert
                              wrote on last edited by
                              #38

                              use this:

                              @
                              QString s = QString("shaperOutI is %1. shaperOutQ is %2.").arg(shaperOutI).arg(shaperOutQ);
                              @

                              Nokia Certified Qt Specialist.
                              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                              1 Reply Last reply
                              0
                              • Z Offline
                                Z Offline
                                ZapB
                                wrote on last edited by
                                #39

                                Gerolf has already shown you how to format the string. If you want it split over two lines then you need to include a "\n" in your string:

                                @QString s = QString("shaperOutI is %1.\nshaperOutQ is %2.").arg(shaperOutI).arg(shaperOutQ);@

                                You may need to set the wordWrap property of the QLabel to true too - I can't recall offhand.

                                Nokia Certified Qt Specialist
                                Interested in hearing about Qt related work

                                1 Reply Last reply
                                0
                                • mzimmersM Offline
                                  mzimmersM Offline
                                  mzimmers
                                  wrote on last edited by
                                  #40

                                  Oh, this is OUTSTANDING. Thanks so much to everyone for their help in this thread. It may not seem like much to anyone else, but this is a major step forward for me.

                                  A final question about all this: can someone explain this line:

                                  @QString s = QString("shaperOutI is %1. shaperOutQ is 2.").arg(shaperOutI).arg(shaperOutQ);@

                                  What's going on with the consecutive .arg calls?

                                  I've got a ton of other questions now, but they're not apropos of this particular thread, so...I'll bundle them into a new thread. This one, I think we can mark solved (except I don't remember how to do that).

                                  Thanks again!

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    giesbert
                                    wrote on last edited by
                                    #41

                                    a qstring object has a method called arg which replaces %1 by its value and returns a temporary object. if on this temp object, another arg is called, it replaces all instances of %2 by its value and so on. Afaik, up to 99 :-)

                                    Nokia Certified Qt Specialist.
                                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                    1 Reply Last reply
                                    0
                                    • mzimmersM Offline
                                      mzimmersM Offline
                                      mzimmers
                                      wrote on last edited by
                                      #42

                                      Interesting...thanks.

                                      So...how do I mark this solved? With a tag?

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        giesbert
                                        wrote on last edited by
                                        #43

                                        go to your first post, click edit and change the title :-)
                                        Just add [Solved] in front

                                        Nokia Certified Qt Specialist.
                                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          goetz
                                          wrote on last edited by
                                          #44

                                          [quote author="Gerolf" date="1301503305"]a qstring object has a method called arg which replaces %1 by its value and returns a temporary object. if on this temp object, another arg is called, it replaces all instances of %2 by its value and so on. Afaik, up to 99 :-)[/quote]

                                          The rationale behind the %1 %2 and so on is, that these strings are regularly translatable and the placeholders need not be integers or numbers but also strings. In some languages, things must be reordered to result in a valid sentence. So you can the write

                                          @
                                          QString x = QString("%2 is before %1).arg("first").arg("second");
                                          @

                                          The resulting string is "second is before first".

                                          http://www.catb.org/~esr/faqs/smart-questions.html

                                          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