Results 1 to 5 of 5

Thread: Using function from another class

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Using function from another class

    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)

  2. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using function from another class

    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.

  3. #3
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using function from another class

    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:

    Qt Code:
    1. void MainWindow::sendButtonClickHandler()
    2. {
    3. QByteArray ba("A"); //data to send
    4. qint64 bw = 0; //bytes really writed
    5. //bw = 0;
    6. bw = MyDevice->write(ba);
    7. std::cout << bw;
    8. }
    To copy to clipboard, switch view to plain text mode 

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

    Cheers!
    /Tottish
    Last edited by Tottish; 8th April 2010 at 08:33. Reason: added code

  4. #4
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using function from another class

    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

  5. The following user says thank you to kuzulis for this useful post:

    Tottish (8th April 2010)

  6. #5
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using function from another class

    Thanks! I'll check it out!
    /Tottish

    EDIT: Ey! That was exactly what I was looking for! Thanks a lot mate!
    /Tottish
    Last edited by Tottish; 8th April 2010 at 11:54.

Similar Threads

  1. QtConncurrent - calling function within the class
    By jacek_ in forum Qt Programming
    Replies: 5
    Last Post: 28th October 2009, 17:37
  2. Problem with the put() function of QFtp class
    By whyisosad in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2009, 10:03
  3. Replies: 3
    Last Post: 16th May 2007, 11:07
  4. function 'connect' always look super class for slots.
    By Intaek Lim in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2007, 13:38
  5. Problems calling C function in C++/Qt class
    By Rayven in forum General Programming
    Replies: 2
    Last Post: 2nd June 2006, 21:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.