QT Designer Issue



  • This is really a strange issue that I'm having that I thought would be a simple thing but it is really giving me a headache. I've got an LCDNumber display widget that I'm trying to write to. I've found some sample code that updates the a clock every second.

    void DigitalClock::showTime()
    {
    QTime time = QTime::currentTime();
    QString text = time.toString("hh:mm:ss");
    setDigitCount(8);
    if ((time.second() % 2) == 0)
    {
    text[5] = ' ';
    }
    display(text);
    // ui->lcdNumber->display(text);
    }

    I've included the //ui-->lcdNumber->display(text) as an example of what I'm trying to do. The following works just fine:

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    ui->lcdNumber->display(text);
    }

    Can anyone explain to me how I can get the DigitalClock section to update the lcdNumber box I created in QT creator?

    Thanks!



  • You can create a signal in DigitalClock that will send the data and a slot in MainWindow that will receive it.

    QObject::connect(yourDigitalClock, SIGNAL(yourSignal(QString)),
                     yourMainWindow, SLOT(setDisplay(QString)));


  • Thanks for your reply! I've spent awhile on this and I could use more help. I've got the following

    void DigitalClock::showTime()
    {
    QTime time = QTime::currentTime();
    QString text = time.toString("hh:mm:ss");
    if ((time.second() % 2) == 0)
    text[2] = ' ';
    display(text);
    }

    I need to pass the QString "text" to a lcdNumber box in the MainWindow and I've tried multiple configurations but I'm just not sure how it works. Could you please fix the what I've done wrong?

    QObject::connect(showTime(), SIGNAL(time(Qstring)), MainWindow(), SLOT(ui->lcdNumber->Display(QString)));
    

    It gives a "No instance of overloaded function "QObject::connect" matches the argument list". I tried the following

    QObject connect(DigitalClock, SIGNAL(time(Qstring)), MainWindow(), SLOT(Display(QString)));

    and it gives me a "expected a type specifier" for the SIGNAL and the SLOT


  • Lifetime Qt Champion

    Hi,

    The SLOT macro only takes the slot name with argument type like shown in @killerman's example


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.