How pass the data from dialog box to mainwindow



  • Hi Volker

    I have no solution and no idea how pass the data from dialog box to mainwindow. give the code.

    [andreyc EDIT]: I moved this thread from "this one":http://qt-project.org/forums/viewthread/10614/ because that thread is 3 years old.



  • Hi Pawan Pal ,
    Welcome to Qt Devnet ,
    Create an object of QMainwindow inside the QDialog class, You should pass your data into the constructor.
    e.g;

    //inside QDialog class (.cpp)

    #include "main.h"
    int data1,data2;
    Main *main=new Main(this,data1,data2);

    and then in Main(QMainWindow) class constructor add 2 parameters, int,int.

    here is your main class
    //in.h file
    class Main:public QMainWindow
    {
    Main(QWidget *parent,int,int);

    }
    //in .cpp file

    Main::Main(QWidget *parent,int d1,int d2) :
    QMainWindow(parent)
    {
    setupUi(this);

    qDebug() << d1 << d2 ;   //Here is your data of Qdialog
    

    }
    This is Rough Code
    Hope it will help you :)



  • Hi Sumit

    Thanks for this code but, I am not understand you are not explain clearlly.
    why not give to me simple example.
    Actually my Ques. is when i push the button the text in text Edit transfer to the another window.

    Thanks and Regards
    Pawan



  • The example that i have given to you is very simple.
    For this You need to work on SIGNAL and SLOT ;
    your problem is very basic.
    Just try to get basic knowledge from tut and docs.
    if not solved then find various link/tutorial available on net.
    Hope it helps.



  • I know Single Slot function. already i used this mechanism ok but its not work



  • Hi
    This is my code, how to used 'strlen' command. I want display the number of character.

    string str = "Amazon";

    if(!strlen(str.c_str))
    {
    ui->textEdit->setText(str);

    }



  • You should use QString .

    QString str ="Example"

    int len = str.length();

    hope it helps



  • Hi Everybody
    how used and compare two string. This is my code.

    void MainWindow::start_cummunication()

    {

    if (!strcmp("!PKS",start_cumm) !=0);

    else
    
        ui->textEdit->setText("Error : Communication
        NotEstabilished");
    

    }



  • Hi Sumit

    Thanks, for code but its not working, comeing errror.
    I written this code.

     QString str = "loni";
     int length = str.length();
     ui->lineEdit->setText(length);
    

    Error : invalid conversion from 'int' to 'const char*' [-fpermissive]



  • Try this one
    @
    QString str = “loni”;
    int length = str.length();
    ui->lineEdit->setText(QString("%1").arg(length));
    @



  • Hi Pawam.
    [quote author="Pawan Pal" date="1396583482"]Hi Sumit

    Thanks, for code but its not working, comeing errror.
    I written this code.

     QString str = "loni";
     int length = str.length();
     ui->lineEdit->setText(length);
    

    Error : invalid conversion from 'int' to 'const char*' [-fpermissive]

    [/quote]

    edit your code in one line
    ui->lineEdit->setText(QString::number(length));
    Hope it helps



  • Thanks Sumit

    Its working



  • Thanks andreyc

    your code is working



  • Plz Help me


Log in to reply
 

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