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. In QT i have function xyz() and i need to return QImage and QString both?
Forum Updated to NodeBB v4.3 + New Features

In QT i have function xyz() and i need to return QImage and QString both?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 750 Views 2 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.
  • A Offline
    A Offline
    amarism
    wrote on last edited by VRonin
    #1

    In the function xyz(), I am calculating the string value and number of image and I need to return all the value like string and image. So, What I need to take the return type so they will take all value?

     try
        {
            m_ImgPath = Array[i];
            QByteArray m_path = m_ImgPath.toLocal8Bit();
            char* ImagePath = m_path.data();
    
          obj *m_ThumpDCMReader = obj::New();
            TReader->SetFileName(ImagePath);
            TReader->Update();
            //const QString string = NULL;
            const char *str_uchar = TReader->GetMetaData()->GetAttributeValue(DC::string).GetCharData();
            string = QString::fromUtf8((char *)str_uchar);
            SPointer<ImageData> imageData = TReader->GetOutput();
            if (!imageData) { return QImage(); }
    
            /// \todo retrieve just the UpdateExtent
            int width = imageData->GetDimensions()[0];
            int height = imageData->GetDimensions()[1];
    
            QImage image(width, height, QImage::Format_RGB32);
            QRgb *rgbPtr =  reinterpret_cast<QRgb *>(image.bits()) + width * (height - 1);
            unsigned char *colorsPtr = reinterpret_cast<unsigned char *>(imageData->GetScalarPointer());
            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    *(rgbPtr++) = QColor(colorsPtr[0], colorsPtr[1], colorsPtr[2]).rgb();
                    colorsPtr += imageData->GetNumberOfScalarComponents();
                }
    
                rgbPtr -= width * 2;
            }
            return (Image,string)
        }
        catch (...) { return QImage(); }
    }
    

    SO what I need to add the return type. So, they will return multiple data.

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

      Hi,

      Either create a small structure containing your data or use std::tuple.

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

      A 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        Either create a small structure containing your data or use std::tuple.

        A Offline
        A Offline
        amarism
        wrote on last edited by
        #3

        @SGaistI am using QPair<QString , QImagre> and return qMakePair(string,image);
        but the problem is how to receive the qMakePair value ??

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

          Right, I forgot about QPair.

          It's just:

          QPair<QString , QImage> returnValue = xyzy();
          

          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
          2
          • A Offline
            A Offline
            amarism
            wrote on last edited by
            #5

            I have one another class, I want to use the value inside the class and I will make QString as string and QImage as image and I want to update the value inside the string and image. How i will update the same value inside it.

            mrjjM 1 Reply Last reply
            0
            • A amarism

              I have one another class, I want to use the value inside the class and I will make QString as string and QImage as image and I want to update the value inside the string and image. How i will update the same value inside it.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @amarism
              Hi
              You need to make access to it in some form or another.
              like

              #include <QPair>
              #include <QDebug>
              
              using MyPair = QPair<QString, QImage >; // to make it better to read
              class DataClass {
                MyPair ThePair; // your pair data
               public:
                DataClass() { // constructor. adds something to the pair
                  ThePair.first = "first";
                  ThePair.second = QImage(); // blank image
                }
                MyPair& getPair() { // access function. returning a reference to the pair
                  return ThePair;
                }
              };
              
              int main(int argc, char* argv[]) {
                QApplication a(argc, argv);
              
                DataClass dc;
                MyPair& pair = dc.getPair();
                qDebug() << "org:"  << pair.first;
                // change it
                pair.first = "the string";
                pair.second = QImage();
                qDebug() << "changed:" << pair.first;
              

              output
              org: "first"
              changed: "the string"

              1 Reply Last reply
              2

              • Login

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