Results 1 to 5 of 5

Thread: Help me with "connect"

  1. #1
    Join Date
    May 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Help me with "connect"

    Qt Code:
    1. QCheckBox *ledek[64];
    2. int ledcounter=0;
    3. for(int i=0;i<8;i++)
    4. {
    5. for(int l=0;l<8;l++)
    6. {
    7. ledek[ledcounter]=new QCheckBox(this);
    8. ledek[ledcounter]->setGeometry(40+(20*i), 60+(20*l), 20, 20);
    9. ledek[ledcounter]->show();
    10. MainWindow::connect(ledek[ledcounter], SIGNAL(stateChanged(int)), this, SLOT(kuldes(ledcounter+100)));
    11. ledcounter++;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    there is a problem in the connect line, it says expected token ")" got ";", but it compiles, also it can't connect to the slot, which is a function made by me, it says this: QObject::connect: No such slot MainWindow::kuldes(ledcounter+100) in ../kettodesledmatrix/mainwindow.cpp:32
    QObject::connect: (receiver name: 'MainWindow')

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help me with "connect"

    The SIGNAL and SLOT macros take function signatures only, i.e. the function name and the list of argument types.
    You have "ledcounter+100" in your SLOT macro, but "ledcounter+100" is not a valid C++ type.

    Cheers,
    _

  3. #3
    Join Date
    May 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Help me with "connect"

    the kuldes function:
    void MainWindow::kuldes(int asd)
    {
    for(int n = 0; n != sizeof asd; ++n)
    {
    output.append((char)((asd & (0xFF << (n*8))) >> (n*8)));
    }
    qDebug() << output;
    serial->write(output);
    }
    how should i pass the numbers?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help me with "connect"

    QSignalMapper.

    Cheers,
    _

  5. #5
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help me with "connect"

    You cannot connect stateChanged() to kuldes() this way. stateChanged() signals that the checkbox has been checked (argument = 1) or unchecked (argument = 0). So kuldes() gets only 0 or 1 from stateChanged(). If you want to pass some integer value, you need to use some variable visible in kuldes() while processing stateChanged(). One possibility is deriving your own checkbox with ledcounter as an additional data member, defining your own signal, say MyStateChanged, connecting stateChanged to yourself a whenever the state changes, update ledcounter and emit MyStateChanged(). Now, connect MyStateChanged to kuldes(). kuldes() can now get the right checkbox using sender() and see the ledcounter.

    The correct connect() at line 10 should be:
    Qt Code:
    1. MainWindow::connect(ledek[ledcounter], SIGNAL(stateChanged(int)), this, SLOT(kuldes(int)));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 24th December 2015, 13:33
  2. Replies: 1
    Last Post: 20th November 2015, 10:02
  3. QSqlError("", "Parameter count mismatch", "")
    By Alberto7 in forum Newbie
    Replies: 2
    Last Post: 9th October 2015, 22:09
  4. Replies: 3
    Last Post: 16th March 2015, 07:31
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.