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. close(int fd) not recognized in QT both fcntl.h and unistd.h are included
Forum Updated to NodeBB v4.3 + New Features

close(int fd) not recognized in QT both fcntl.h and unistd.h are included

Scheduled Pinned Locked Moved Solved General and Desktop
qtcreator 4.9.1closeqt5.11
18 Posts 5 Posters 2.3k 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.
  • KroMignonK KroMignon

    @vicky_mac said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

    hi i am doing some memory read and write using mmap and open function in my application.
    But when i am going for closing the file descriptor close() functions is not recognized and program densest compile.

    You have to specify the namespace :: to use standard open() function:

    int fd = ::open("/dev/mem",O_RDWR|O_SYNC);
    

    EDIT, of course the same is also for close() and all standard functions, to ensure using std function and not same called function is current name space:

    int fd = ::open("/dev/mem",O_RDWR|O_SYNC);
    int* add =(int*)::mmap(NULL,2048,PROT_READ | PROT_WRITE,MAP_SHARED,dh,0);
    //now some operation as needed
    ::munmap(add,2048);
    ::close(fd);
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #3

    @KroMignon
    The OP claims his (only) error is on close().

    @vicky_mac
    Depending (C, C++), either what have you #included or do you need ::close()?

    1 Reply Last reply
    0
    • V vicky_mac

      hi i am doing some memory read and write using mmap and open function in my application.

      But when i am going for closing the file descriptor close() functions is not recognized and program densest compile.

      #include"mainwindow.h"
      #include<unistd.h>
      #include<fcntl.h>
      
      MainWindow::ReadMem()
      {
      int fd = open("/dev/mem",O_RDWR|O_SYNC);
      int* add =(int*)mmap(NULL,2048,PROT_READ | PROT_WRITE,MAP_SHARED,dh,0);
      //now some operation as needed
      munmap(add,2048);
      close(fd);/// this line not compiling
      }
      
      

      // Nomatching function to call function close```
      code_text

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @vicky_mac

      man 2 close
      

      and include the header file mentioned there.

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

      KroMignonK 1 Reply Last reply
      0
      • jsulmJ jsulm

        @vicky_mac

        man 2 close
        

        and include the header file mentioned there.

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #5

        @jsulm said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

        and include the header file mentioned there.

        According to thread title, unistd.h has been included, so it should not be the problem.

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        jsulmJ JonBJ 2 Replies Last reply
        0
        • KroMignonK KroMignon

          @jsulm said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

          and include the header file mentioned there.

          According to thread title, unistd.h has been included, so it should not be the problem.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @KroMignon Yeah, careful reading is something I should do more often :-)

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

          1 Reply Last reply
          0
          • KroMignonK KroMignon

            @jsulm said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

            and include the header file mentioned there.

            According to thread title, unistd.h has been included, so it should not be the problem.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #7

            @KroMignon
            I had not noticed that information in the title. (Was it added later?! :) )

            @vicky_mac
            What you do not say is where --- inside which class --- your code is located. You are likely to need ::close() as @KroMignon has said, did you at least try it?

            V 1 Reply Last reply
            0
            • JonBJ JonB

              @KroMignon
              I had not noticed that information in the title. (Was it added later?! :) )

              @vicky_mac
              What you do not say is where --- inside which class --- your code is located. You are likely to need ::close() as @KroMignon has said, did you at least try it?

              V Offline
              V Offline
              vicky_mac
              wrote on last edited by
              #8

              @JonB hi Joh
              I have edited my question with include and function detail. Please advise what exactly needs to be done.

              JonBJ 1 Reply Last reply
              0
              • V vicky_mac

                @JonB hi Joh
                I have edited my question with include and function detail. Please advise what exactly needs to be done.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #9

                @vicky_mac said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

                Please advise what exactly needs to be done.

                @JonB said:

                You are likely to need ::close() as @KroMignon has said, did you at least try it?

                Your plain close() will be MainWinow::close().

                V 1 Reply Last reply
                1
                • JonBJ JonB

                  @vicky_mac said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

                  Please advise what exactly needs to be done.

                  @JonB said:

                  You are likely to need ::close() as @KroMignon has said, did you at least try it?

                  Your plain close() will be MainWinow::close().

                  V Offline
                  V Offline
                  vicky_mac
                  wrote on last edited by
                  #10

                  @JonB
                  Hi Jon,

                  I am getting the same error even after MainWindow::close(fd)

                  jsulmJ JonBJ 2 Replies Last reply
                  0
                  • V vicky_mac

                    @JonB
                    Hi Jon,

                    I am getting the same error even after MainWindow::close(fd)

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @vicky_mac @JonB did not say you need to use MainWindow::close(fd)! What he means is that your MainWindow probably has its own close() method nd if you write close(...) that one is used.
                    Why don't you simply try what @KroMignon suggested?!

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

                    V 1 Reply Last reply
                    2
                    • jsulmJ jsulm

                      @vicky_mac @JonB did not say you need to use MainWindow::close(fd)! What he means is that your MainWindow probably has its own close() method nd if you write close(...) that one is used.
                      Why don't you simply try what @KroMignon suggested?!

                      V Offline
                      V Offline
                      vicky_mac
                      wrote on last edited by
                      #12

                      @jsulm

                      Hi jsulm,

                      Sorry to bother again but i don't know which namespace to use in this case i tried std:: that also doesn't work.
                      Can you please suggest which namespace to be used. Thank you

                      jsulmJ KroMignonK 2 Replies Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by Christian Ehrlicher
                        #13

                        @vicky_mac said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

                        Can you please suggest which namespace to be used. Thank you

                        So hard to read @KroMignon 's answer?

                        You have to specify the namespace :: to use standard open() function:
                        int fd = ::open("/dev/mem",O_RDWR|O_SYNC);

                        Basic c++ stuff ...

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • V vicky_mac

                          @jsulm

                          Hi jsulm,

                          Sorry to bother again but i don't know which namespace to use in this case i tried std:: that also doesn't work.
                          Can you please suggest which namespace to be used. Thank you

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          @vicky_mac Did you read what @KroMignon suggested?

                          ::close(fd);
                          

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

                          1 Reply Last reply
                          0
                          • V vicky_mac

                            @jsulm

                            Hi jsulm,

                            Sorry to bother again but i don't know which namespace to use in this case i tried std:: that also doesn't work.
                            Can you please suggest which namespace to be used. Thank you

                            KroMignonK Offline
                            KroMignonK Offline
                            KroMignon
                            wrote on last edited by
                            #15

                            @vicky_mac said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

                            Hi jsulm,
                            Sorry to bother again but i don't know which namespace to use in this case i tried std:: that also doesn't work.
                            Can you please suggest which namespace to be used. Thank you

                            In C++, there are namespaces to prevent name conflicts (cf. https://en.cppreference.com/w/cpp/language/namespace).
                            When you are writing code in a C++ class, the default namespace is the current class.
                            So when you are calling a close() function, the compiler first try to find this function in the current namespace.

                            To avoid this, you have to specify full namespace. In case of "standard functions" like close(int), the namespace is empty. So the fullname of standard open(int), in C++ is ::open().

                            This are C++ basics, it is always helpful to learn the basics ;)

                            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                            V 1 Reply Last reply
                            3
                            • KroMignonK KroMignon

                              @vicky_mac said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

                              Hi jsulm,
                              Sorry to bother again but i don't know which namespace to use in this case i tried std:: that also doesn't work.
                              Can you please suggest which namespace to be used. Thank you

                              In C++, there are namespaces to prevent name conflicts (cf. https://en.cppreference.com/w/cpp/language/namespace).
                              When you are writing code in a C++ class, the default namespace is the current class.
                              So when you are calling a close() function, the compiler first try to find this function in the current namespace.

                              To avoid this, you have to specify full namespace. In case of "standard functions" like close(int), the namespace is empty. So the fullname of standard open(int), in C++ is ::open().

                              This are C++ basics, it is always helpful to learn the basics ;)

                              V Offline
                              V Offline
                              vicky_mac
                              wrote on last edited by
                              #16

                              @KroMignon
                              Thanx for the reply kromignon.

                              I am familiar with C but not much C++. I think i'll have to read the basics of C++ for using QT

                              KroMignonK 1 Reply Last reply
                              0
                              • V vicky_mac

                                @KroMignon
                                Thanx for the reply kromignon.

                                I am familiar with C but not much C++. I think i'll have to read the basics of C++ for using QT

                                KroMignonK Offline
                                KroMignonK Offline
                                KroMignon
                                wrote on last edited by
                                #17

                                @vicky_mac said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

                                I think i'll have to read the basics of C++ for using QT

                                Yes, or you will have a very hard time.
                                I know it, because I had the same learning way. I start with C/Assembler for years before programming in C++.
                                Event if they seem identical, they are definitively not.

                                Programming C++ as a C developer is not the right way to do.
                                Take time to learn C++ basics will save you many days later.

                                Qt is a C++ framework, so it is mandatory to understand C++ to be able to use Qt.

                                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                1 Reply Last reply
                                2
                                • V vicky_mac

                                  @JonB
                                  Hi Jon,

                                  I am getting the same error even after MainWindow::close(fd)

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by
                                  #18

                                  @vicky_mac said in close(int fd) not recognized in QT both fcntl.h and unistd.h are included:

                                  I am getting the same error even after MainWindow::close(fd)

                                  Both @KroMignon and I said from the start and multiple times to try ::close(fd);. Same with ::open(). How much clearer than that can one be?

                                  If you want to be "safe", every single C (not C++) function you want to use should be ::function().

                                  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