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. How can I move my normal c++ main() function code to qt main function?
Forum Update on Tuesday, May 27th 2025

How can I move my normal c++ main() function code to qt main function?

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 3 Posters 6.9k 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.
  • A Ashish Tupate
    9 Jan 2018, 06:41

    @jsulm I dont know why but this error again even if these functions are inside encodercount.h:

    'initEncoder' was not declared in this scope
    initEncoder();
    ^
    'stopEncoder' was not declared in this scope
    stopEncoder();
    ^

    #ifndef ENCODERCOUNT_H
    #define ENCODERCOUNT_H
    #include <rotary_encoder.hpp>
    
    
    namespace Encoder {
    class EncoderCount;
    }
    
    class EncoderCount
    {
    public:
        explicit EncoderCount();
        ~EncoderCount();
    
        void initEncoder();
        void stopEncoder();
    
    };
    
    
    #endif // ENCODERCOUNT_H
    
    
    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 9 Jan 2018, 06:44 last edited by
    #21

    @Ashish-Tupate Please think about what you are doing: you put both functions inside EncoderCount class! And then you try to call them as if they would be simple functions.
    You should learn C++.
    It should be like this:

    #ifndef ENCODERCOUNT_H
    #define ENCODERCOUNT_H
    #include <rotary_encoder.hpp>
    
    void initEncoder();
    void stopEncoder();
    

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    A 1 Reply Last reply 9 Jan 2018, 06:55
    2
    • J jsulm
      9 Jan 2018, 06:44

      @Ashish-Tupate Please think about what you are doing: you put both functions inside EncoderCount class! And then you try to call them as if they would be simple functions.
      You should learn C++.
      It should be like this:

      #ifndef ENCODERCOUNT_H
      #define ENCODERCOUNT_H
      #include <rotary_encoder.hpp>
      
      void initEncoder();
      void stopEncoder();
      
      A Offline
      A Offline
      Ashish Tupate
      wrote on 9 Jan 2018, 06:55 last edited by
      #22

      @jsulm Yes you are right but you have to help me out.Again I got the error :
      return-statement with a value, in function returning 'void' [-fpermissive]
      if (gpioInitialise() < 0) return 1;
      ^

      J 1 Reply Last reply 9 Jan 2018, 07:05
      0
      • A Ashish Tupate
        9 Jan 2018, 06:55

        @jsulm Yes you are right but you have to help me out.Again I got the error :
        return-statement with a value, in function returning 'void' [-fpermissive]
        if (gpioInitialise() < 0) return 1;
        ^

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 9 Jan 2018, 07:05 last edited by
        #23

        @Ashish-Tupate "but you have to help me out" - no I don't have to.
        You should really learn C++ and read the error messages carefully. What you are asking is completely unrelated to Qt.
        Change

        if (gpioInitialise() < 0) return 1;
        

        to

        if (gpioInitialise() < 0) return;
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply 9 Jan 2018, 07:06
        2
        • J jsulm
          9 Jan 2018, 07:05

          @Ashish-Tupate "but you have to help me out" - no I don't have to.
          You should really learn C++ and read the error messages carefully. What you are asking is completely unrelated to Qt.
          Change

          if (gpioInitialise() < 0) return 1;
          

          to

          if (gpioInitialise() < 0) return;
          
          A Offline
          A Offline
          Ashish Tupate
          wrote on 9 Jan 2018, 07:06 last edited by Ashish Tupate 1 Sept 2018, 07:07
          #24

          @jsulm Thank you for your help.

          1 Reply Last reply
          0

          21/24

          9 Jan 2018, 06:44

          • Login

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