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]Qvector Problem instansiate Thanks ALL
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Qvector Problem instansiate Thanks ALL

Scheduled Pinned Locked Moved General and Desktop
31 Posts 5 Posters 12.3k 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.
  • P Offline
    P Offline
    p-himik
    wrote on last edited by
    #2

    At what point your program actually crashes? When you create the QVector or whent you try to append to it?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      toho71
      wrote on last edited by
      #3

      on isEmpty()

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

        That needs more code to evaluate. From what I see, it is correct. In which function do you call isEmpty? Where do you create it? where is the constructor, ...?

        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
        • P Offline
          P Offline
          p-himik
          wrote on last edited by
          #5

          Do other containers or QVector with other type cause crash?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            toho71
            wrote on last edited by
            #6

            My h.file
            @#ifndef GLOBALPARAMS_H
            #define GLOBALPARAMS_H
            #include <QVector>
            #include <QList>
            #include <QTime>
            #include <clpresetloadstestvalues.h>

            class GlobalParams
            {
            public:
            GlobalParams();
            ~GlobalParams();
            enum Tester {Starttest, Loadtest, Batterytest, ParallellToMains, MainsFailureTEst, PresetLoadsTest , Notest};

            void setTest(int);
            int getTest();
            
            void testRunning(bool );
            bool getTestRunning();
            
            void setNBState(int s);
            void setGBState(int s);
            void setRunningState(int s);
            void setRunningMode(int s);
            
            int getNBState();
            int getGBState();
            int getRunningState();
            int getRunningMode();
            
            void addValuesToLoadsTestTemp(int,int,int);
            
             double getRandomNumbers(float max, float min);
             QString roundnumbers(double dNumber);
            

            private:
            int testTyp;

            int NBState;
            int GBState;
            int RunningState;
            int RunningMode;
            bool TestRunning;
            
            QVector <ClPresetLoadsTestValues> presetVector;
            

            };
            @

            in my cpp file
            @void GlobalParams::addValuesToLoadsTestTemp(int kw, int min, int sec)
            {
            ClPresetLoadsTestValues p;
            p.setKW(kw);
            p.setMin(min);
            p.setSec(sec);

            if (presetVector.isEmpty())
                qDebug() << "Empty";
             else
                qDebug() << "SIZE " << presetVector.size() ;
            
            
            presetVector.append(p);
             qDebug() << "appendad";
            

            }

            @

            My h.file to the object I want to save

            @class ClPresetLoadsTestValues
            {
            public:
            ClPresetLoadsTestValues();
            ClPresetLoadsTestValues(int k, int m, int s);
            ~ClPresetLoadsTestValues();

            //set
            void setKW(int k);
            void setMin(int k);
            void setSec(int k);

            //get
            int getKw();
            int getMin();
            int getSec();

            private:
            int kw;
            int min;
            int sec;

            };
            @
            I tried with a Struct also but same crash

            1 Reply Last reply
            0
            • T Offline
              T Offline
              toho71
              wrote on last edited by
              #7

              I'm using a vector in a different place in my application and there is no problem to use.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kxyu
                wrote on last edited by
                #8

                Check for that: you declare your presetVector like a value, so that constructor of it is called before the constructor of GlobalParams. So may be the object of GlobalParams haven't been instantiated yet?

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  toho71
                  wrote on last edited by
                  #9

                  I have tried to do like this also.

                  @QVector <.theClass> *myVector;
                  @
                  and in the constructor of globalparams

                  @myVector = new QVector<theClass>();
                  @
                  but same crash ;

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Kxyu
                    wrote on last edited by
                    #10

                    Ok, once again, check if constructor of GlobalParams is called, add there qDebug()<<"anything";

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      toho71
                      wrote on last edited by
                      #11

                      It's the first thing I do in my program.

                      I got a lot of parameters in that object that I use in other places so thats no problem.

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

                        Please provide a small, complete, compilable and runnable sample program. We can have a look if and where it crashes ourselves then.

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

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          toho71
                          wrote on last edited by
                          #13

                          Now I'm back to my Work and will send a small application with this Vector problem.
                          I have put some QDebug lines in the code to:

                          But where could I upload the program

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            p-himik
                            wrote on last edited by
                            #14

                            I think that any file sharing hosting will be suitable. For example try http://rghost.net/

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

                              look for a file hoster (e.g. gitorious.org, but you need a logon) or any other

                              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
                              • T Offline
                                T Offline
                                toho71
                                wrote on last edited by
                                #16

                                I have discovered a problem know that is a little confusing.

                                When I try to append a Object or a struct thats not in the class where the vector is the program crashes but when I put a struct inside the class and append this to the vector it works fine

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  toho71
                                  wrote on last edited by
                                  #17

                                  Here is not the TAR file to test

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    p-himik
                                    wrote on last edited by
                                    #18

                                    Your code works without any crashes. I didn't do any changes though.

                                    1 Reply Last reply
                                    0
                                    • T Offline
                                      T Offline
                                      toho71
                                      wrote on last edited by
                                      #19

                                      Try again with this code
                                      I had comment the problem spots in the last code.
                                      The new one is here
                                      "Vectorproblems":http://rghost.net/31386231

                                      pls

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        p-himik
                                        wrote on last edited by
                                        #20

                                        toho71 either you have to read more about C++ or you did horrible typo. Here it is:
                                        @myClass::~myClass()
                                        {
                                        delete this;
                                        }@

                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          toho71
                                          wrote on last edited by
                                          #21

                                          copy and paste is the to magic words
                                          Ok now it works again.

                                          I have to look in my header prj to and see if this is the magic case.

                                          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