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. Problem with new object from another class
Forum Updated to NodeBB v4.3 + New Features

Problem with new object from another class

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.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.
  • M Offline
    M Offline
    Marcel92
    wrote on 26 Jun 2017, 17:48 last edited by
    #1

    Hi
    I am sure it´s a minor problem, but i cant find a solution to my problem.
    I am trying to declare a new object from another class and then use a method.
    The other class has an overloaded constructor and i think thats my problem.

    #pragma once
    /*!  ----------------------------------------------------------------------------
    * Name:	  				AnalyseEKG.h
    * Autor:				Ritthaler
    * Version:				1.0
    * Copyright: 			Team 3KG
    * Description:			Softwarepraktikum SoSe 2017
    *
    * Abhängige Dateien: AnalyseEKG.cpp
    * Änderungen:
    *
    * Name             | Version        |   Datum/Zeit        |Grund
    *    Ritthaler     |    1.0         |    07.05.17         |Erstellung
    *    Ritthaler     |    1.1         |    07.06.17         |Bearbeitung
    *    Ritthaler     |    1.2         |    10.06.17         |Bearbeitung
    *                  |                |                     |
    * ----------------------------------------------------------------------------*/
    #ifndef _ANALYSE_EKG_
    #define _ANALYSE_EKG_
    #include <vector>
    #include <string>
    #include <AnalyseLagetyp.h>
    #include <AnalyseSTEMI.h>
    
    using namespace std;
    
    class AnalyseEKG
    {
    
    
    
    public:
    
    	/*!
    	* Aufgabe:  Konstruktor
    	*
    	* Input:	Zweidimensionaler double-Vektor
    	*
    	* Output:  -
    	*
    	*/
    
        AnalyseEKG(std::vector<std::vector<double>> v);
    	~AnalyseEKG();
    	/*!
    	* Aufgabe: Liefert die Anzahl der R-Zacken zurück
    	*
    	* Input:	 -
    	*
    	* Output:  int 
    	*
    	*/
    	int getAnzRZacken(); 
    
    	/*!
    	* Aufgabe: liefert die Herzfrequenz zurück
    	*
    	* Input:	-
    	*
    	* Output:  int HF
    	*
    	*/
    
    	int getHF();
    
    	/*!
    	* Aufgabe: liefert den Lagetyp zurück
    	*
    	* Input:	 -
    	*
    	* Output:  string Lagetyp
    	*
    	*/
    	
        string getLagetyp();
    
    	/*!
    	* Aufgabe: liefert STEMI ja/nein zurück
    	*
    	* Input:	 -
    	*
    	* Output:  bool 
    	*
    	*/
    
    	bool getSTEMI();
    
    
    private:
       // vector<double> vAuswertung; //!Vektor mit EKG-Ableitungen: Zeit I II III aVR aVF aVL
        std::vector<std::vector< double > > vAuswertung;
    
    
    	/*!
    	* Aufgabe: Markierung der Q- und R-Zacken im EKG
    	*
    	* Input:	-
    	*
    	* Output:  -
    	*
    	*/
    	void MarkiereEKG(); 
    	
    
    
        std::vector<int> PositionQZacke;	//! Speichert Positionen der Q-Zacken
        std::vector<int> PositionRZacke;	//! Speichert Positionen der R-Zacken
    
    
    
    	
    
    };
    
    
    
    #endif //_ANALYSE_EKG___
    
    
    /*! ----------------------------------------------------------------------------
    * Name: mainwindow.h
    * Autor:    Sk...., Marcel
    *           Stangl, Florian
    *
    * Version: 0.9
    * Erstellung: 02.05.2017
    * Copyright: Team 3KG
    * Description: Softwarepraktikum SoSe 2017
    *
    * Abhängige Dateien: Befunder.cpp, Person.h, Person.cpp, EKG2File.h, EKG2File.cpp
    *                   qcustomplot.h, qcustomplot.cpp
    *
    * Aufgabe: GUI Erstellen und alle Operationen ausführen
    *
    * Änderungen:
    *
    * Name					| Version	| Datum/Zeit	|Grund
    * | | |
    * | | |
    * ----------------------------------------------------------------------------*/
    
    #pragma once
    
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    //! @brief Include für das QT
    #include <QMainWindow>
    //! @brief Include der abhängigen Dateien (Klassen)
    #include "befunder.h"
    #include "patient.h"
    #include "person.h"
    #include "EKG2File.h"
    #include "AnalyseEKG.h"
    #include "AnalyseLagetyp.h"
    #include "AnalyseSTEMI.h"
    //! @brief Include für Graphenausgabe
    #include <qcustomplot.h>
    #include <QVector>
    #include <vector>
    
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
    //! @brief Konstruktor
        explicit MainWindow(QWidget *parent = 0);
    //! @brief Destruktor
        ~MainWindow();
    
    //! @brief  Slots zur Verarbeitung der Befehle auf der Oberfläche
    private slots:
    
    
    private:
    
    //! @brief Objekt Vektor für den Plot
        EKG2File werteVector;
    
        
    //! @brief Objekt für die Herzfrequenz
        AnalyseEKG herzfrequenz (std::vector<std::vector<double>> hfVector); //////////////  here is the problem. he doesnt recognize "herzfrequenz"(it´s not colored red). but theres no error message here.
    //! @brief Objekt für den Lagetyp
        AnalyseEKG lagetyp; /////// here i want to do the same. he recognizes "lagetyp" (colors it red). but thats wrong, because he needs a vector.
    //! @brief Objekt für den STEMI
        //AnalyseEKG stemi;
    
    
    #endif // MAINWINDOW_H
    
    
    void MainWindow::einthoven_plotten()
    {  
    
        std::vector<std::vector<int>> hfVectors;
        graph_erstellen();
    
        do
        {
           
            plotVector = werteVector.createEKGVector(i);
            x.append(plotVector[0]);
            abl1.append(plotVector[1]);
            abl2.append(plotVector[2]);
            abl3.append(plotVector[3]);
    
            ui->Plot1->graph(0)->setData(x,abl1);
            ui->Plot1->replot();
    
            ui->Plot2->graph(0)->setData(x,abl2);
            ui->Plot2->replot();
            ui->Plot3->graph(0)->setData(x,abl3);
            ui->Plot3->replot();
    
            hfVectors = herzfrequenz.getHF(); /////// i want to use it here, but the error message says "D:\Programme\QT\MeineProjekte\3KG_3.0\mainwindow.cpp:792: Fehler: '((MainWindow*)this)->MainWindow::herzfrequenz' does not have class type
             hfVectors = herzfrequenz.getHF();
                         ^
    ////////////////////////////////
            if(plotVector[0] == max)
            {
                QApplication::processEvents();
                max = max + 1;
                min = min + 1;
    
                ui->Plot1->xAxis->setRange(min,max);
                ui->Plot1->replot();
    
                ui->Plot2->xAxis->setRange(min,max);
                ui->Plot2->replot();
    
                ui->Plot3->xAxis->setRange(min,max);
                ui->Plot3->replot();
    
            }
    
            i++;
        }while(i != 10000 || stoppVariable != 0);
    }
    

    ive marked the problem lines with ///////////

    Thanks in advance.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 26 Jun 2017, 18:04 last edited by mrjj
      #2

      @Marcel92 said in Problem with new object from another class:

      Hi, easy way around it is just to use pointer
      in mainwindows.h
      AnalyseEKG *herzfrequenz=NULL;

      then before any use, you do
      std::vector<std::vector<double>> v; // note its local.
      herzfrequenz = new AnalyseEKG (v); // give it the vector

      Alternatively you can assign such members via constructor list
      http://en.cppreference.com/w/cpp/language/initializer_list

      You can also add a second constructor taking no arguments and add a
      setVector function so you can add vector later. (before use)

      Note that it seems to copy the vector to its private variable. ( i assume its by design)
      Note2: The einthoven_plotten contains a loop that if very long, will hang the application.

      1 Reply Last reply
      3
      • M Offline
        M Offline
        Marcel92
        wrote on 26 Jun 2017, 18:42 last edited by
        #3

        Hey @mrjj
        Thanks for your answer.
        I tried your pointer solution

        AnalyseEKG *herzfrequenz=NULL;
        
        
            std::vector<std::vector<double>> v; // note its local.
            herzfrequenz = new AnalyseEKG (v); // give it the vector
        

        But then it gives me the error : herzfrequenz does not name a type?? I dont get it.

        M 1 Reply Last reply 26 Jun 2017, 18:51
        0
        • M Marcel92
          26 Jun 2017, 18:42

          Hey @mrjj
          Thanks for your answer.
          I tried your pointer solution

          AnalyseEKG *herzfrequenz=NULL;
          
          
              std::vector<std::vector<double>> v; // note its local.
              herzfrequenz = new AnalyseEKG (v); // give it the vector
          

          But then it gives me the error : herzfrequenz does not name a type?? I dont get it.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 26 Jun 2017, 18:51 last edited by mrjj
          #4

          @Marcel92
          Did you add
          #include "AnalyseEKG.h"
          in mainwindow.h
          so it knows the type for
          AnalyseEKG *herzfrequenz=NULL;

          also the using code is inside a member function of mainwinow?

          #include "AnalyseEKG.h"
          
          class MainWindow : public QMainWindow
          {
              Q_OBJECT
          
          public:
              explicit MainWindow(QWidget *parent = 0);
              ~MainWindow();
          void Using();
          private:
              Ui::MainWindow *ui;
          AnalyseEKG *herzfrequenz=NULL;
          };
          
          then in mainwindow.cpp
          
          MainWindow::void Using() {
           std::vector<std::vector<double>> v; // note its local.
           herzfrequenz = new AnalyseEKG (v); // give it the vector. Note you should call delete on this when finished using it
          }
          
          1 Reply Last reply
          3
          • M Offline
            M Offline
            Marcel92
            wrote on 26 Jun 2017, 19:18 last edited by
            #5

            Oh i wasnt using it in a member function -.-

            Thank you so much!

            M 1 Reply Last reply 26 Jun 2017, 19:47
            0
            • M Marcel92
              26 Jun 2017, 19:18

              Oh i wasnt using it in a member function -.-

              Thank you so much!

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 26 Jun 2017, 19:47 last edited by mrjj
              #6

              @Marcel92
              Np :)

              Note that each time you call Using() , a new class is created.
              If that not what you want then use this not so pretty construct

              if (! herzfrequenz)
              herzfrequenz = new AnalyseEKG (v); // will only run once.

              but make sure it says
              AnalyseEKG *herzfrequenz=NULL; in .h file ( or nullptr)

              1 Reply Last reply
              3

              3/6

              26 Jun 2017, 18:42

              • Login

              • Login or register to search.
              3 out of 6
              • First post
                3/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved