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]creat functions in mainwindow.cpp
Forum Update on Monday, May 27th 2025

[Solved]creat functions in mainwindow.cpp

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.1k 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.
  • S Offline
    S Offline
    serj90
    wrote on 20 May 2014, 21:31 last edited by
    #1

    Hello can someone please explain to me how to declare function if I need calculate something .

    @int test(int a,int b){
    int c;
    c=a*b;
    return c;
    }

    void MainWindow::on_pushButton_clicked() {
    int aa=4;
    int bb=0;
    int cc=0;
    cc=test(aa,bb); } @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on 20 May 2014, 21:47 last edited by
      #2

      Your example looks ok.
      I would declare test() as part of MainWindow but in general it looks ok.
      What is wrong with your code now?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        serj90
        wrote on 20 May 2014, 22:14 last edited by
        #3

        I get this error :
        S:\C&C++ programing\QT\MASTER\MASTER-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug..\MASTER\mainwindow.cpp:160: ошибка: 'test' was not declared in this scope

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on 20 May 2014, 23:35 last edited by
          #4

          Is function test() defined in mainwindow.cpp?
          Is it defined before first use?

          If not then you need to declare it before first use.

          • mainwindow.cpp
            @
            int test(int, int); // <-- this is a declaration

          void MainWindow::on_pushButton_clicked()
          {
          int aa=4;
          int bb=0;
          int cc=0;
          cc=test(aa,bb);
          }

          int test(int a,int b)
          {
          int c;
          c=a*b;
          return c;
          }
          @

          1 Reply Last reply
          0
          • S Offline
            S Offline
            serj90
            wrote on 21 May 2014, 15:49 last edited by
            #5

            Thank you this was my problem. :)

            1 Reply Last reply
            0

            1/5

            20 May 2014, 21:31

            • Login

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