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. [SOLVED]Qt Widget Pointer to class
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Qt Widget Pointer to class

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.9k 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.
  • H Offline
    H Offline
    hexenbrennen
    wrote on last edited by
    #1

    Hi

    i have an old console application which shall not be changed! but i want to change the output class so that a listwidget will add the output as new items

    so this widget will call the old classes these will call the output class how do i connect the output class with the widget to add items to the listwidget?

    Construct

    MainWindow->calls->old classes->call occasionally->output class->adds item in listwidget of MainWindow

    code of output class:
    @output::output()
    {
    }

    void output::send(std::string text){
    ///*

    QString qtext=QString::fromStdString(text);
    
    QObject::connect(this,SIGNAL(sends(QString)),&w,SLOT(set_protocol(QString)));    //&w is not known !
    
    emit this->sends(qtext);
    //*/
    
    ///*
    std::cout<<text<<std::endl;
    //*/
    

    }@

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hexenbrennen
      wrote on last edited by
      #2

      solved this with global pointer to MainWindow

      @MainWindow * pw;

      output::output()
      {
      }

      void output::send(std::string text){
      ///*
      QString qtext=QString::fromStdString(text);
      QObject::connect(this,SIGNAL(sends(QString)),pw,SLOT(set_protocol(QString)));
      emit this->sends(qtext);
      QObject::disconnect(this,SIGNAL(sends(QString)),pw,SLOT(set_protocol(QString)));

      //*/
      
      ///*
      std::cout<<"hi "<<text<<std::endl;
      //*/
      

      }@

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        Why not just connect from the MainWindow to the output::sends signal?

        This is how signals and slots are supposed to be used in the first place (the receiver connects to the sender, not the other way round).

        As your design already introduces a dependecy on MainWindow in output, you do not need a signal at all, just use <code>pw->set_protocol(qtext)</code>. The triumvirate connect, emit, disconnect already screams that you meant calling a method in the first place.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hexenbrennen
          wrote on last edited by
          #4

          thx Lukas

          that was really stupid from me!

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            You're welcome.

            Feel free to change your post title to '[Solved] ...' to indicate that your question has been answered and that there is a solution inside.

            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