close(int fd) not recognized in QT both fcntl.h and unistd.h are included
-
@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? -
@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 beMainWinow::close()
. -
@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?! -
@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 ...
-
@vicky_mac Did you read what @KroMignon suggested?
::close(fd);
-
@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 youIn 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 aclose()
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 standardopen(int)
, in C++ is::open()
.This are C++ basics, it is always helpful to learn the basics ;)
-
@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.
-
@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()
.