Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create instance of class?
Forum Updated to NodeBB v4.3 + New Features

Create instance of class?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 525 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MScottM
    wrote on last edited by
    #1

    I'm trying to update a program that was written in Qt a long time ago (~2001) and update it to Qt6, both as a learning exercise and as a program that would be useful to me. It is written in a collection of modules that handle chunks of the functionality.

    There is a serial port component that was written to poll the serial port - I'm trying to change it to be asynchronous. That part seems to be straight forward. The next module 'up the chain' handles data coming from and going to the port. I'm trying to update some connect statements and am having trouble.

    Issue is commented in code below:

    'pcrio.h'

    class PcrIO : public QObject
    {
        Q_OBJECT
    
    public:
        explicit PcrIO(); // <--tried making constructor generic
        //explicit PcrIO( QSerialPort *serialPort, QObject *parent = nullptr );
    

    'pcrproxy.h'

    class PcrProxy : public QObject
    {
        Q_OBJECT
    
    public:
        PcrProxy( QObject *parent=0, const char *name=0 );
        ~PcrProxy();
    
    private:
        // need to create instance of class
        //PcrIO( *pcrIO );
        PcrIO *pcrIO = new PcrIO();
    
    

    problem is here, in pcrproxy.cpp:

    PcrProxy::PcrProxy(QObject *parent, const char *name)
        : QObject( )
    {
        // connect to PcrIO to send/receive messages
        // trying to update the connect statements to 'new' style
       // error on next line is 'pcrIO is not a class, namespace or enumeration'
        connect( this, &PcrProxy::sendMessage, &pcrIO, &pcrIO::write());
        //connect( this, SIGNAL( sendMessage(const char *, int)), &pcrIO, SLOT( write(const char *, int)));
    
        connect( pcrIO, SIGNAL( radioMessage(const char *, int)), this,	SLOT( radioMessageSlot(const char *, int)) );
    
        connect( pcrIO, SIGNAL( disconnected() ), this,	SLOT( ResetSerialPort() ) );
    

    What am I doing wrong?
    BTW - entire project is on github.

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      Hi @MScottM,

      error on next line is 'pcrIO is not a class, namespace or enumeration'

      Your PcrIO class has a capital P. ie the first connect should be something like:

      connect( this, &PcrProxy::sendMessage, pcrIO, &PcrIO::write);
      

      Where I've dropped the & from the third argument (pcrIO is already a pointer), replaced pcrIO with PcrIO in the fourth argument (to use a class name, not an instance variable), and dropped the () a the end (its a function pointer, not an invocation).

      Cheers.

      1 Reply Last reply
      3
      • M Offline
        M Offline
        MScottM
        wrote on last edited by
        #3

        @Paul-Colby,

        Thank you for the answer! I spent way too much time trying to figure it out...

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved