PDA

View Full Version : Using function from another class



Tottish
7th April 2010, 17:01
Hello!
I'm using an example called sreader from QSerialDevice in my project to get some SerialCommunication going with a microcontroller. I've managed to implement the reader with good functionality but when I try to add a send-function I get in trouble.

I'm using the sreader.h-file (almost) as is from the example where a Reader class is defined. When I try to call the write function like so:

bw = MyDevice->write(ba);

I get the information that MyDevice isn't declared in this scope. Fair enough, but when I try Reader::MyDevice it says that Reader is not a class or type.
So how do I do this? Am I barking up the wrong tree or is it just a syntax error?

Thanks a lot!
/Tottish (Very much C++ newbie)

waynew
8th April 2010, 01:45
Need to see your code to help you out. I am using QSerialDevice to successfully read and write to a serial port with no problems.
Will help you out if I can.

Tottish
8th April 2010, 08:21
Hey waynew!
Could I possibly take a sneek peek at your code?
The problem is that I've derived my code from the examples. Unfortunately, there is no example that implements both the sending and receiving ability of the class and the sreader (creates a slot that is activated when data is received) is mostly implemented in a .h file.
I use the sreader.h (located in the examples folder) as is with the exception of the ReadOnly changed to ReadWrite.
What I then try to do is to reach the QSerialDevice that is defined in sreader.h from the mainwindow.cpp. This is a standard GUI application with a mainwindow with a button connected to the slot (sendButtonClickHandler). When this buttn is clicked I want to send The Character "A" on the bus. This code works in the example "writer" but in that file "MyDevice" is defined in the same file...
The code looks like this:



void MainWindow::sendButtonClickHandler()
{
QByteArray ba("A"); //data to send
qint64 bw = 0; //bytes really writed
//bw = 0;
bw = MyDevice->write(ba);
std::cout << bw;
}


As I said earlier when I try using Reader::MyDevice it says that Reader is not a class...

Cheers!
/Tottish

kuzulis
8th April 2010, 09:28
2 Tottish

Use the library from SVN : svn checkout svn://scm.fireforge.net/svnroot/qserialdevice
(or call link http://fireforge.net/snapshots.php?group_id=199)

There, I added new examples AnyMaster and AnySlave. See examples AnySlave, I think this is what you need.

PS: Warning! In the SVN there are many differences from the release 0.2.0. Be careful! ;)

----
Denis

Tottish
8th April 2010, 09:31
Thanks! I'll check it out!
/Tottish

EDIT: Ey! That was exactly what I was looking for! Thanks a lot mate!
/Tottish