Qt: How to connect a QPushButton clicked() signal of a “DialogClass1” to kill a QProcess in a “MainClass2”?



  • Hi, I have the source code:

    @void Processmethod()
    {

    QDialog *ProcessMessage = new QDialog;      
    Ui::DialogProcessMessage Dialog;        //polymorphy      
    Dialog.setupUi(ProcessMessage);              
    ProcessMessage->setModal(true);
    ProcessMessage->setAttribute(Qt::WA_DeleteOnClose); 
    connect(ProcessMessage->pushButtonAbort, SIGNAL(clicked()), &Prozess, SLOT(kill()));  //DOESN'T WORK
    ProcessMessage->show();
    
    processmethodONE(); 
    

    }

    void processmethodONE()
    {
    QString ProcessCommand = "w8 " + blablubli";

    Prozess.setWorkingDirectory(Path);         //QProcess "Prozess" is globaly defined  
    Prozess.setStandardOutputFile(Path);       //in my class
    QEventLoop loop;                                                                 
    connect(&Prozess, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
    connect(&Prozess, SIGNAL(finished(int, QProcess::ExitStatus)), &loop, SLOT(quit()));
    Prozess.start(ProcessCommand);
    loop.exec();
    
    QProcess::ExitStatus Status = Prozess.exitStatus(); 
    
    if (Status == 0)
    {
        std::cout <<"Exit-Status: " << Status << " File created!" << std::endl;
    }
    else
    {
    

    std::cout << "Exit-Status: " << Status << " Error-Code: " << Prozess.error() << "Process failed!" << std::endl;
    }
    }@

    What I want to do, is to kill the QProcess "Prozess" by one of the dialogs pushButtons "pushButtonAbort". The class "Ui::DialogProcessMessage" can't be edited/specified since it is the class directly constructed by the QtDesigner Ui-File and therefore will be overwritten anytime the Ui-File is edited with QtDesigner.
    As you can see I tried the connection method
    @connect(&ProcessMessage->pushButtonAbort, SIGNAL(clicked()), &Prozess, SLOT(kill()));@

    , but I only get the error code
    @Form.cpp: In member function 'int subclassGUI Processmethod() ": Form.cpp: 5152:29: error: class QDialog has no member named 'pushButtonAbort' make: *** [Form.o] Error 1@

    How can I handle this? greetings



  • Example solution: create a class, which will use your Ui::DialogProcessMessage. Then in this class write a method to return a pointer to a button.



  • Doesn't this work ?

    @
    QDialog* processMessage = new QDialog;
    Ui::DialogProcessMessage dialogUI = new Ui::DialogProcessMessage();
    dialogUI->setupUi(processMessage);
    processMessage->setModal(true);
    processMessage->setAttribute(Qt::WA_DeleteOnClose);
    connect(dialogUI->pushButtonAbort, SIGNAL(clicked()), &Prozess, SLOT(kill()));
    @



  • (at) KA510 : Nope, does not work. I only get:

    @Form.cpp: In member function 'int GUIsubclass Processmethod () ":
    Form.cpp: 5150:19: error: base operand of '->' has non-pointer type 'Ui :: Dialog Process Message "
    make: *** [Form.o] Error 1@

    @Hostel: I will try this if there really should be no other solution.

    Addition:
    problem solved now. KA510 suggestion worked just with
    connect(Dialog.pushButtonAbort, SIGNAL(clicked()), &Prozess, SLOT(kill()));

    So I just had to use a . instead of a ->. Because Dialog is obviously no pointer object (see error message above)



  • quote author="Streight" date="1333458229" KA510 : Nope, does not work. I only get:

    @Form.cpp: In member function 'int GUIsubclass Processmethod () ":
    Form.cpp: 5150:19: error: base operand of '->' has non-pointer type 'Ui :: Dialog Process Message "
    make: *** [Form.o] Error 1@
    [/quote]

    Sorry my fault forgot to change the type of the dialogUI object in my code. This should work.
    @
    QDialog* processMessage = new QDialog;
    Ui::DialogProcessMessage* dialogUI = new Ui::DialogProcessMessage();
    dialogUI->setupUi(processMessage);
    processMessage->setModal(true);
    processMessage->setAttribute(Qt::WA_DeleteOnClose);
    connect(dialogUI->pushButtonAbort, SIGNAL(clicked()), &Prozess, SLOT(kill()));
    @



  • xD I just changed the "->" into a "." . Is there any advantage/disadvantage in pointer objects? Thx for the solution anyway



  • Depends on how you use the Dialog and where you create it. But I guess in your case you can just allocate the object on the stack. The advantage is also the disadvantage, you have to take care of deleting the object yourself.

    Glad I could help.


Log in to reply
 

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