Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Button



  • Hi, I'm new in Qt .I want to create a simple qt gui application .So i want to create a button and by clicking this button the user can get a message. How can I create this .. any help.??



  • in the UI from just drag and drop the button and also lineedit or textarea what ever u need to display the message . then note the object name of the pushbutton and the lineedit
    then

    decalre the function in the header file void on_but_clicked()

    in the mainwindow.cpp add the Functio

    @
    void Mainwidget::on_but_clicked()
    {
    ui->line->settext("message");
    }
    @

    assume:
    objectnameof the button = but
    lineeditobject = line

    [EDIT: code formatting, please wrap in @-tags, Volker]



  • Void MainWindow name instead of MainWidget



  • Depends.
    If you've already got a main window with a button, you could use this:

    @
    CMainWindow::CMainWindow()
    {
    ...

    connect(m_ui->pButton, SIGNAL(pressed()), this, SLOT(SlotShowMessage()));
    }

    void CMainWindow::SlotShowMessage()
    {
    QMessageBox::warning(this, tr("title"), tr("text"));
    }
    @

    If you're starting from scratch, you could use one of the tutorial projects (there should be at least one that demonstrates how to create a mainwindow) and base your application on it, then use code similar to what I've posted above.



  • or u can directly edit signal slot option in edit menu



  • thanks...



  • Hi, I’m new in Qt .I want to create a simple qt gui application .So i want to create a button and by clicking this button the user can get a message. How can I create this ..
    Again the same question with out using drag and drop option...
    Any help plz...


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Please don't revive old thread. Did you follow Qt's documentation tutorials and examples ? They provide all the informations you need to get started


Log in to reply