User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

closing serial port in QT

Sat Oct 01, 2016 7:07 am

HI
I am designing a GUI with QTcreator and I need to use Serial port on PI2.
I don't use any library and I write my code only with linux file function.
for example I have a buttom that opens the Serial Port :

Code: Select all

int fd= open (...)
if (fd < 0) ..
else...
....
I want another buttom that close the port
after opening the port (in a simple C program) I can close the port with following code:

Code: Select all

close(fd);
my problem : I want use this function in QTcreator for click slot of a buttom but QT cant recognize CLOSE() function with argumant
if I use close() (without any argumants) my GUI closed !
how I can close serial port with a BUTTOM ???
If your Dreams Don't Scare You , They Aren't Big Enough

scotty101
Posts: 3809
Joined: Fri Jun 08, 2012 6:03 pm

Re: closing serial port in QT

Sat Oct 01, 2016 8:54 am

Don't directly call the close function with a button press.

Create a separate function that contains the close(fd) and call that.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

Re: closing serial port in QT

Sat Oct 01, 2016 12:25 pm

scotty101 wrote:Don't directly call the close function with a button press.

Create a separate function that contains the close(fd) and call that.
Thanks a lot ! :) :) :)
If your Dreams Don't Scare You , They Aren't Big Enough

User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

Re: closing serial port in QT

Sun Oct 02, 2016 8:19 am

I have another problem,If you can please help me :
I have a TextBrowser in my form and I want to show recieving buffer of serial port on it
I want a function that check the serial port for recieving always
and show the recieving in textbrowser (like a serial terminal)

I can recieve 10 char in a simple program with :

Code: Select all

count = read (fd,buff,10);
if (count > 0){
....
}
Excuse me for bad English :|
If your Dreams Don't Scare You , They Aren't Big Enough

Return to “C/C++”