Results 1 to 5 of 5

Thread: I am new in Qt !!!

  1. #1
    Join Date
    Jun 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default I am new in Qt !!!

    Hello to everyone !!!
    I created a project with qt creator with the name "asd", with
    Base class: QDialog
    Class name: asdDialog
    Header file: asdDialog.h
    Source file: asdDialog.cpp
    Form file: asdDialog.ui

    In the form I added
    1. QPushButton with text "HELLO"
    2.QLineEdit

    I tried to connect them by-code like this way:
    I put the connect function in the "asdDialog.cpp", in the constractor "asdDialog::asdDialog(QWidget *parent)" , under "ui->setupUi(this);"

    connect(ui->button, SIGNAL(clicked()),
    ui->lineEdit, SLOT(writeMessage("HELLO")));

    As you see I want to create a new slot for "ui->lineEdit" which does not exist ...

    Where can I declare and write the code of "writeMessage("HELLO")"

    Is it possible without using the "right click --> Go to slot" ??
    If you advice me with "right click --> Go to slot", then when can I use the "connect method" ??

    Anyone can help me ?? Thanks in advance !!! (I am from Greece - Volos)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I am new in Qt !!!

    Hey, good football match yesterday

    You can't add slots to already existing classes thus it is not possible to add a slot to "ui->lineEdit". You need to add that slot to your asdDialog class and modify your connect() statement accordingly. Moreover you can't pass arguments to the slot you want to call from within the connect() statement. You have to create a generic slot that will call ui->lineEdit->setText("HELLO").
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: I am new in Qt !!!

    My friend thank you for the reply !! It was a good match indeed !

    I tried to put my slot in asdDialog.h class like this way:
    public slots:
    void writeMessage();

    And I wrote the code in asdDialog.cpp like this:
    void asdDialog::writeMessage()
    {
    ui->lineEdit->setText("HELLO");
    }

    And the connect:
    connect(ui->button, SIGNAL(clicked()),
    ui->lineEdit, SLOT(writeMessage()));
    It said:

    Object::connect: No such slot QLineEdit::writeMessage()
    Object::connect: (sender name: 'button')
    Object::connect: (receiver name: 'lineEdit')

    Have I done the "You need to add that slot to your asdDialog class and modify your connect() statement accordingly", correct?

    Why slots cannot have args , in that you said "you can't pass arguments to the slot ..."
    There are slot with args , aren't there?

    Sorry friend but how can I create a generic slot? What is it ??

    Friend sorry about the way I speak, I don't speak very good english (first time in a foreign forum)

  4. #4
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: I am new in Qt !!!

    your football team is professional indeed.
    i enjoyed watching it.
    good luck

  5. #5
    Join Date
    Jun 2012
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: I am new in Qt !!!

    @ Ali Reza

    Thank you very much my friend (although I don't watch fanatically football....)

    @ wysota


    Good friend I FOUND IT !!!
    I created a slot to the initial asdDialog form ....

    e.g. in asdDialog.h

    class asdDialog : public asdQDialog
    {
    ...............
    public slots:
    void writeMessage();
    ...............
    };

    And the connect, in asdDialog.cpp

    asdDialog::asdDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui:ialog)
    {
    ..............
    connect(ui->pushButton, SIGNAL(clicked()),
    this, SLOT(writeMessage()));
    }

    void Dialog::writeMessage()
    {
    ui->lineEdit->setText("LINUX");
    }

    Watch my friend "this" refers to initial form, as you advised me ....

    Thank you very much for your advises and for your help !!! tomkat

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.