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. How to extract variable created in the function to the variable outside of the function?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 235 Views
  • 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
    jbbb
    wrote on 9 Apr 2021, 13:21 last edited by
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Apr 2021, 19:04 last edited by
      #2

      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
      1
      • J Offline
        J Offline
        jbbb
        wrote on 11 Apr 2021, 06:05 last edited by
        #3

        how is it done?
        any example?

        1 Reply Last reply
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 11 Apr 2021, 07:13 last edited by
          #4

          @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
          0

          1/4

          9 Apr 2021, 13:21

          • Login

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