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] Using function parameter Class object
Forum Updated to NodeBB v4.3 + New Features

[solved] Using function parameter Class object

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 3.0k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    You are using a type that has not been declared yet in your func slot (which itself is declared before the genYapi). Also note that genYapi it's a private type and you are using it in a public slot.

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

    K 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      You are using a type that has not been declared yet in your func slot (which itself is declared before the genYapi). Also note that genYapi it's a private type and you are using it in a public slot.

      K Offline
      K Offline
      kingsta
      wrote on last edited by
      #3

      @SGaist

      Firstly, thanks for quick response. You often do it...

      I can't understand. Can you explain with code?

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

        genYapi belongs to MainWindow so you have to rewrite the function signature like:

        void MainWindow::func(MainWindow::genYapi &gen){
        qDebug() << "gen.value: " << gen.value;
        }
        

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

        K 1 Reply Last reply
        0
        • SGaistS SGaist

          genYapi belongs to MainWindow so you have to rewrite the function signature like:

          void MainWindow::func(MainWindow::genYapi &gen){
          qDebug() << "gen.value: " << gen.value;
          }
          
          K Offline
          K Offline
          kingsta
          wrote on last edited by
          #5

          @SGaist I did but I got same errors.

          error: C2664: 'void MainWindow::func(genYapi &)' : cannot convert argument 1 from 'MainWindow::genYapi' to 'genYapi &'
          error: C2664: 'void MainWindow::func(genYapi &)' : cannot convert argument 1 from 'MainWindow::genYapi [5]' to 'genYapi &'
          error: C2511: 'void MainWindow::func(MainWindow::genYapi &)' : overloaded member function not found in 'MainWindow'

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

            You have to declare it before you use it

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

            K 1 Reply Last reply
            0
            • SGaistS SGaist

              You have to declare it before you use it

              K Offline
              K Offline
              kingsta
              wrote on last edited by kingsta
              #7

              @SGaist said:

              before you use

              Do you say like that?

              cpp file
              void MainWindow::func(MainWindow::genYapi &gen){
              qDebug() << "gen.value: " << gen.value;
              }

              MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
              {
              ui->setupUi(this);
              func(gen1);
              }

              MainWindow::~MainWindow()
              {
              delete ui;
              }

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

                No, you have to declare genYapi earlier. Again, note that the way you do it currently, no other classes than MainWindow will be able to use that struct.

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

                K 1 Reply Last reply
                0
                • SGaistS SGaist

                  No, you have to declare genYapi earlier. Again, note that the way you do it currently, no other classes than MainWindow will be able to use that struct.

                  K Offline
                  K Offline
                  kingsta
                  wrote on last edited by kingsta
                  #9

                  @SGaist

                  I change code and It works! Thank you a lot!

                  I have a question again. This func function allows me that func(gen[0]) or func(gen[50]) etc. How can I use func(gen) ? I want to control all of array members at once. I look for solution on Internet, but I can't do it. Class Inheritance is complicated for me...

                  header file
                  ...
                  class MainWindow : public QMainWindow
                  {
                  Q_OBJECT

                  public:
                  explicit MainWindow(QWidget *parent = 0);
                  ~MainWindow();

                  private:
                  Ui::MainWindow *ui;

                  struct genYapi{
                      double deger;
                      bool elitMi=0;
                      double amacFonkSnc;
                  
                      int basSayisi;
                  }gen1[EN_FAZLA_BIREY], gen2[EN_FAZLA_BIREY], gen3[EN_FAZLA_BIREY];
                  

                  public slots:
                  void func(MainWindow::genYapi &gen);
                  };
                  ...

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

                    Pass a pointer to your struct and loop over your array. You can also consider using e.g. QVector.

                    But again, func can't be called from outside MainWindow since genYapi is a private structure.

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

                    K 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Pass a pointer to your struct and loop over your array. You can also consider using e.g. QVector.

                      But again, func can't be called from outside MainWindow since genYapi is a private structure.

                      K Offline
                      K Offline
                      kingsta
                      wrote on last edited by
                      #11

                      @SGaist Thank you so much brother. Have a good day..

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

                        You're welcome !

                        Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

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

                        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