Results 1 to 4 of 4

Thread: Function not Declared in This Scope - error

  1. #1

    Question Function not Declared in This Scope - error

    Hi folks, I'm relatively new to Qt programming and have come across an error stating that a function I had created was 'not declared in this scope'.
    However, I don't see how this is the case as I included the header file in which it was declared into the offending file.

    The error I get is:

    ' adcreader.cpp: In constructor ‘ADCreader::ADCreader()’:
    adcreader.cpp:79:29: error: ‘gz_clock_ena’ was not declared in this scope
    gz_clock_ena(GZ_CLK_5MHz,5);'

    The file in which the error comes from is called 'adcreader.cpp' and I have included the relevant sections to the error below, any help would be greatly appreciated. I do apologise for the length of the post.

    ```cpp
    Qt Code:
    1. 1 #include "adcreader.h"
    2. 2 #include <QDebug>
    3. 3
    4. 4 #include "gpio-sysfs.h"
    5. 5 #include <fcntl.h>
    6. 6 #include <sys/ioctl.h>
    7. 7 #include <linux/types.h>
    8. 8 #include <linux/spi/spidev.h>
    9. 9 #include <assert.h>
    10. 10 #include "gz_clk.h"
    11. 11
    12. 12 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
    13. 13
    14. 14 #define MAX_SAMPLES 65536
    15. 15
    16. 16 ADCreader::ADCreader()
    17. 17 {
    18. 18 int ret = 0;
    19. ...........................
    20.  
    21. 77 // enable master clock for the AD
    22. 78 // divisor results in roughly 4.9MHz
    23. 79 // this also inits the general purpose IO
    24. 80 gz_clock_ena(GZ_CLK_5MHz,5);
    25.  
    26. .....
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 
    ```

    The file in which I declared the function is called gz_clk.h and I have included its code below:

    ```cpp
    Qt Code:
    1. 22 #ifndef GZ_CLK_H
    2. 23 #define GZ_CLK_H
    3. 24 #include <QtCore>
    4. 25 #include<bcm2835.h>
    5. 26
    6. 27 #define GZ_CLK_5MHz 0
    7. 28 #define GZ_CLK_125MHz 1
    8. 29
    9. 30 //int gz_clock_ena(int speed, int divider);
    10. 31 //int gz_clock_dis();
    11. 32
    12. 33 //#endif // GZ_CLK_H
    13. 34
    14. 35 class gz_clk : public QObject
    15. 36 {
    16. 37
    17. 38 Q_OBJECT
    18. 39
    19. 40 public:
    20. 41 gz_clk();
    21. 42 int gz_clock_ena(int speed, int divider);
    22. 43 int gz_clock_dis();
    23. 44
    24. 45
    25. 46 };
    26. 47
    27. 48 #endif // GZ_CLK_H
    To copy to clipboard, switch view to plain text mode 
    ```

    The file in which I implemented the function was in a file called gz_clk.cpp and its code is below:

    ```cpp
    Qt Code:
    1. 22 #include "gz_clk.h"
    2. 23 #include <stdio.h>
    3. 24 #include <stdlib.h>
    4. 25 #include <unistd.h>
    5. 26 #include <QtCore>
    6. 27
    7. 28 #define GZ_CLK_BUSY (1 << 7)
    8. 29
    9. 30 gz_clk::gz_clk()
    10. 31
    11. 32 {
    12. 33 }
    13. 34
    14. 35 int gz_clk::gz_clock_ena(int speed, int divisor) {
    15. 36 int speed_id = 6;
    16. 37 if (speed < GZ_CLK_5MHz || speed > GZ_CLK_125MHz) {
    17. 38 printf("gz_clock_ena: Unsupported clock speed selected.\n");
    18. 39 printf("Supported speeds: GZ_CLK_5MHz (0) and GZ_CLK_125MHz (1).");
    19. 40 exit(-1);
    20. 41 }
    21. 42 if (speed == 0) {
    22. 43 speed_id = 1;
    23. 44 }
    24. 45 if (divisor < 2) {
    25. 46 printf("gz_clock_ena: Minimum divisor value is 2.");
    26. 47 exit(-1);
    27. 48 }
    28. 49 if (divisor > 0xfff) {
    29. 50 printf("gz_clock_ena: Maximum divisor value is %d.", 0xfff);
    30. 51 exit(-1);
    31. 52 }
    32. 53 if (bcm2835_init() !=1) {
    33. 54 printf("gz_clock_ena: Failed to initialize I/O\n");
    34. 55 exit(-1);
    35. 56 }
    36. 57 usleep(5);
    37. 58 bcm2835_gpio_fsel(RPI_GPIO_P1_07, BCM2835_GPIO_FSEL_ALT0);
    38. 59 *(bcm2835_clk + 0x1C) = 0x5A000000 | speed_id; // GPCLK0 off
    39. 60 while (*(bcm2835_clk + 0x1C) & GZ_CLK_BUSY) {} // Wait for BUSY low
    40. 61 *(bcm2835_clk + 0x1D) = 0x5A002000 | (divisor << 12); // set DIVI
    41. 62 *(bcm2835_clk + 0x1C) = 0x5A000010 | speed_id; // GPCLK0 on
    42. 63 return 0;
    43. 64
    44. 65 }
    45. 66
    46. 67 int gz_clk::gz_clock_dis() {
    47. 68 if (bcm2835_init() !=1) {
    48. 69 printf("gz_clock_dis: Failed to initialize I/O\n");
    49. 70 exit(-1);
    50. 71 }
    51. 72 bcm2835_gpio_fsel(RPI_GPIO_P1_07, BCM2835_GPIO_FSEL_INPT);
    52. 73 return 0;
    53. 74 }
    To copy to clipboard, switch view to plain text mode 
    ```
    Last edited by anda_skoa; 8th April 2016 at 09:13. Reason: missing [code] tags

  2. #2
    Join Date
    Apr 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Function not Declared in This Scope - error

    Hi,

    You have not invoked the function with the gz_clock_ena(...) with an object of class gz_clk. You can only use the function directly if you have inherited ADCreader from gz_clk. This has nothing to do with Qt.
    Just a suggestion, please read the posting norms and use code formatting while posting.

  3. #3

    Default Re: Function not Declared in This Scope - error

    Quote Originally Posted by Prady_80 View Post
    Hi,

    You have not invoked the function with the gz_clock_ena(...) with an object of class gz_clk. You can only use the function directly if you have inherited ADCreader from gz_clk. This has nothing to do with Qt.
    Just a suggestion, please read the posting norms and use code formatting while posting.
    Hi, thanks a lot for your suggestion - a bad mistake. However, before checking here I managed to find another solution to my problem. The problem seemed to be a linking problem rather than a compiling one. Despite being installed, the library 'bcm2835' was not being properly detected. In the project's '.pro' file, I added the line 'LIBS += -lbcm2835 -lrt' - which allowed the program to compile and link without error.

  4. #4

    Default Re: Function not Declared in This Scope - error

    Good solution!

Similar Threads

  1. Replies: 3
    Last Post: 8th April 2011, 17:09
  2. Variable not declared in this scope error
    By hojoff79 in forum Newbie
    Replies: 1
    Last Post: 30th December 2010, 00:29
  3. Replies: 2
    Last Post: 16th July 2010, 07:17
  4. glutSolidSphere was not declared in this scope error
    By nuts_fever_007 in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2009, 04:56
  5. error: 'connect' was not declared in this scope ??
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2007, 15:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.