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.2k 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.
  • 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 Online
    JonBJ Online
    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 Online
                      JonBJ Online
                      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