Re: serial port programming in qt
Quote:
Do you mean that i need to declare it under protected and use it in the constructor ?
No, you need to declare it as a member variable.
Do you know what a member variable is?
Code:
{
private: //depends on your needs, this can be any access mode
QextSerialPort *m_note;
public:
Widget
( QWidget *parent
=0,
const char *name
=0 );
private:
int mouse;
int mouseidx;
};
Widget
::Widget( QWidget *parent,
const char *name
)m_note(NULL)
{
setMinimumSize(640,480 );
m_note= new QextSerialPort("/dev/ttyS0");
if(note)
{
m_note->setBaudRate(BAUD115200);
m_note->setParity(PAR_NONE);
m_note->setDataBits(DATA_8);
m_note->setStopBits(STOP_1);
m_note->open(IO_ReadOnly);
}
}
Re: serial port programming in qt
high_flyer:
yeah i did as you said. i tried both the ways-private or protected. But no use.:(
Re: serial port programming in qt
Could you be a bit more descriptive?
The access mode has nothing to do with it.
Re: serial port programming in qt
first i tried declaring the Qextserialport as a private member variable, compiled and when i rum the same error came. next i tried declaring it as protected member variable, the same thing happened.
Re: serial port programming in qt
what error? segmentation falut?
Are there any other methods do the Widget class?
Try setting debug messages along the code or run in a debugger and see where the applciation crashes.
EIDT:
Wait, in the code I edited for you, your should change all 'note' instances to 'm_note' did you do that?
Re: serial port programming in qt
Hi,
i solved that problem. i did not declare it in the heap.The following is what i did:
Code:
QextSerialPort note("/dev/ttyS0");
note.setBaudRate(BAUD115200);
note.setParity(PAR_NONE);
note.setDataBits(DATA_8);
note.setStopBits(STOP_1);
note.open(IO_ReadOnly);
With this the application opens without segmentation fault. Now i'm finding out how to read the datas ? the suggestion b1 gave did not work out as there is no member function called read in the Qextserialport.
Anyway thanks a lot for all of your kind response .
Re: serial port programming in qt
What you did is no good.
The serial port gets created on the stack, and dies when the constructor ends.
Use the code I gave you.
Re: serial port programming in qt
high_flyer:
Oops. it still not working. This is my code:
ConnectWidget::ConnectWidget( QWidget *parent, const char *name )
: QWidget( parent, name),m_note(NULL)
{
setBackgroundColor( white );
setMinimumSize(640,480 );
m_note= new QextSerialPort("/dev/ttyS0");
if(m_note)
{
m_note->setBaudRate(BAUD115200);
m_note->setParity(PAR_NONE);
m_note->setDataBits(DATA_8);
m_note->setStopBits(STOP_1);
m_note->open(IO_ReadOnly);
}
printf("\n serial port openned \n");
}
Is this what you suggested?
Re: serial port programming in qt
Quote:
what error? segmentation falut?
Are there any other methods do the Widget class?
Try setting debug messages along the code or run in a debugger and see where the applciation crashes.
And please use code tags.
Re: serial port programming in qt
Sir,
I modified the code. Now i have onely three lines in my code:
Code:
class ConnectWidget
: public QWidget{
public:
ConnectWidget
( QWidget *parent
=0,
const char *name
=0 );
private:
QextSerialPort *m_note;
};
ConnectWidget
::ConnectWidget( QWidget *parent,
const char *name
) : QWidget( parent, name
),m_note
(NULL) {
setMinimumSize(640,480 );
m_note= new QextSerialPort("/dev/ttyS0");
printf("\n serialport openned \n");
}
I have not added the settings of the serial port.As i found that starting from this line the error pops up. the following is the error message:
suse:/home/qtprograms/roughserial # ./roughserial -qws
Connected to VFB server: 640 x 480 x 32
Segmentation fault
suse:/home/qtprograms/roughserial #
Re: serial port programming in qt
Hi B1,
DId you experience any segementation problem in creating the serialport in heap like mine ? i tried your way of declaring also ? but i still could not make it ?
Re: serial port programming in qt
Quote:
I have not added the settings of the serial port.As i found that starting from this line the error pops up.
Do you mean that the program crashes on:
m_note->setBaudRate(BAUD115200); ?
This code should run.
How did you discover on which line the program crashes, what method did you use to debug?
Re: serial port programming in qt
high_flyer:
No , the program crashes in the first line itself. i mean :
m_note= new QextSerialPort("/dev/ttyS0");
I had only this line in my constructor ( as i had posted in the above post). i did not have any other line.
Re: serial port programming in qt
Quote:
I had only this line in my constructor ( as i had posted in the above post). i did not have any other line.
You mean the only line of code in ConnectWidget constructor right?
Does it run if you remove that line as well?
Does it run when this construcotr is empty?
Are you sure you are not trying to use a 'note' or 'm_note' somehwere else in your code?
It would be good if you could post you mail() function.
The problem in your code is not the parts we currently see.
Ofcourse there is also the chance that the QextSerialPort lib is faulty for some reason on your system.
Re: serial port programming in qt
yeah, it runs if i comment that line and place a printf there.And i'm sure i dont use that anywhere in my code.
Quote:
It would be good if you could post you mail() function.
I have not used any thing like this function .
Also i'm using qextserialport-0.8.0 package since only this supports qt-3.3.5 version. remaining packages such as qextserialport-0.9.0,1.0,1.1 supports higher versions of qt. will there be any problem with this version changes ?
Re: serial port programming in qt
Quote:
I have not used any thing like this function .
Sorry, I meant main().
Quote:
yeah, it runs if i comment that line and place a printf there.And i'm sure i dont use that anywhere in my code.
Hmm... then from what you have said so far, it all points to a problem in your QextSerialPort lib.
Quote:
Also i'm using qextserialport-0.8.0 package since only this supports qt-3.3.5 version. remaining packages such as qextserialport-0.9.0,1.0,1.1 supports higher versions of qt. will there be any problem with this version changes ?
What do you mean?
using a Qt4 QextSerialPort with Qt3?
That wont work.
Re: serial port programming in qt
The following in my main():
Code:
int main( int argc, char **argv )
{
ConnectWidget connect1;
a.setMainWidget( &connect1 );
connect1.show();
return a.exec();
}
Quote:
What do you mean?
using a Qt4 QextSerialPort with Qt3?
That wont work.
No i mean i'm using qt-3.3.5 version and the other versions of qextserialport requires header and libraries of qt 4 or greater version.
Re: serial port programming in qt
Well, from what I can see, there is no problem with the code it self.
You can only link QextSerialPort for Qt3 (which is linked against Qt3) with Qt3 applications.
You can only link QextSerialPort for Qt4 (which is linked against Qt4) with Qt4 applications.
Re: serial port programming in qt
yeah as you said the code is right. and qextserialport package is used is also correct i think. i mean(for qt-3.3.5 package i used qextserialport-0.8.0 package).
I think they may have updated these features in the latest versions.And i'm linking qt3 application with qt3 package only.
Re: serial port programming in qt
Quote:
And i'm linking qt3 application with qt3 package only.
That is the way it should be.
Strange.:confused: