Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to extract variable created in the function to the variable outside of the function?

    General and Desktop
    3
    4
    90
    Loading More Posts
    • 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
      jbbb last edited by

      I would like to extract one of my variable(headerbyte) that is stored in a function to be stored in a variable outside of this function.

      QString headerbyte = ();

      DataTable ThemeWidget::generateRandomData(const QByteArray &data) const
      {
      DataTable dataTable;
      QByteArray testdata = data;
      QString headerbyte = testdata.left(10);
      testdata.remove(0,10);
      // generate testdata
      int listCount = 1;
      for (int i(0); i < listCount; i++) {
      DataList dataList;
      float yValue(0);
      int count(0);
      QString datavalue;
      QString checksign;
      for (int j(0); j<136; j++)
      {
      testdata.remove(0,1);
      checksign = testdata.left(1);
      if (checksign == "-"){
      datavalue = testdata.left(7);
      testdata.remove(0,7);
      }
      else{
      datavalue = testdata.left(6);
      testdata.remove(0,6);
      }
      yValue = datavalue.toFloat();
      QPointF value(count, yValue);
      count++;
      dataList << Data(value);
      }
      dataTable << dataList;
      }
      return dataTable;
      }

      How do i go about doing it?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Make your function return both e.g. through a structure or a tuple.

        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 Reply Quote 1
        • J
          jbbb last edited by

          how is it done?
          any example?

          1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            @jbbb said in How to extract variable created in the function to the variable outside of the function?:

            any example?

            Take a c++ book, read about classes. Nothing Qt-specific here, simple c++ basics. Sorry.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply Reply Quote 0
            • First post
              Last post