Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. recover a slot parameter

recover a slot parameter

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 503 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jasser
    wrote on last edited by
    #1

    Hello ,
    In my code I have a slot that receive a type parameter QString , I want to assign the value for this parameter in another variable , or the use DIRECTLY , in another function of the same class .

    in my code the signal is emitted from another class

    help me please and
    thank you

    MyWidget.h

    #ifndef MYWIDGET_H
    #define MYWIDGET_H
    #include"myclass.h"
    #include <QWidget>
    #include <QtWidgets>
    namespace Ui {
    class MyWidget;
    }
    
    class MyWidget : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit MyWidget(QWidget *parent = 0);
        ~MyWidget();
    private:
        Ui::MyWidget *ui;
    signals:
       void redirectData(QString data);
    public slots:
       void sendData();
    private:
       MyClass *myClass; // the object to receive and output the data
    };
    
    #endif // MYWIDGET_H
    

    MyWidget.cpp

    #include "mywidget.h"
    #include "ui_mywidget.h"
    MyWidget::MyWidget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::MyWidget)
    {
        ui->setupUi(this);
        myClass = new MyClass();
    
        connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(sendData()));
        connect(this, SIGNAL(redirectData(QString)), myClass, SLOT(outputData(QString)));
    }
    
    MyWidget::~MyWidget()
    {
        delete ui;
    }
    void MyWidget::sendData()
    {
    
        emit redirectData(ui->lineEdit->text());
        myClass->show();
    
    }
    

    MyClass.h

    #ifndef MYCLASS_H
    #define MYCLASS_H
    #include <QWidget>
    
    namespace Ui {
    class MyClass;
    }
    
    class MyClass : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit MyClass(QWidget *parent = 0);
        ~MyClass();
        QString x;
    private:
        Ui::MyClass *ui;
    signals:
        void send2(QString);
    public slots:
        void outputData(QString data);
    };
    #endif // MYCLASS_H
    

    MyClass.cpp

    #include "myclass.h"
    #include "ui_myclass.h"
    
    MyClass::MyClass(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::MyClass)
    {
        ui->setupUi(this);
        ui->plainTextEdit->insertPlainText(x); // show x in plainTextEdit
    }
    
    MyClass::~MyClass()
    {
        delete ui;
    }
    void MyClass::outputData(QString data){
    
       x=data; // affect data a x 
    }
    

    here is a catch

    catch 1

    I want to display x in qplaintext

    this method is correct but does not fit with the rest of my code

    I want to recover data in x

    MyClass.cpp

    #include "myclass.h"
    #include "ui_myclass.h"
    
    MyClass::MyClass(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::MyClass)
    {
        ui->setupUi(this);
       
    }
    
    MyClass::~MyClass()
    {
        delete ui;
    }
    void MyClass::outputData(QString data){
    
        ui->plainTextEdit->insertPlainText(data); 
    }
    

    here is a catch
    catch 2

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You have to refresh x in your slot and update your QPlainTextEdit accordingly.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved