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. hot to change int to the string type
Forum Updated to NodeBB v4.3 + New Features

hot to change int to the string type

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 1.2k 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    Hi, i'm using qt5.5 on my computer.
    I have a program like below.

    void MainWindow::on_horizontalSlider_volume_valueChanged(int value)
    {
        QString info;
        Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/amixer set Speaker "+value+"%",&info);
        qDebug()<<info;
    }
    

    But it will show the error for me when i compile, it's the content of the error.

    mainwindow.cpp:2697:105: error: invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'
         Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/amixer set Speaker "+value+"%",&info);
    
    

    How can i fix the problem?
    I don't know where did i do wrong?
    Please help!

    J.HilkJ 1 Reply Last reply
    0
    • V victor wang

      Hi, i'm using qt5.5 on my computer.
      I have a program like below.

      void MainWindow::on_horizontalSlider_volume_valueChanged(int value)
      {
          QString info;
          Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/amixer set Speaker "+value+"%",&info);
          qDebug()<<info;
      }
      

      But it will show the error for me when i compile, it's the content of the error.

      mainwindow.cpp:2697:105: error: invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'
           Process::executeProcessSync(QString("sh"),QStringList()<<"-c"<<"/usr/bin/amixer set Speaker "+value+"%",&info);
      
      

      How can i fix the problem?
      I don't know where did i do wrong?
      Please help!

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @victor-wang To convert an Interger into a String is kind of the part basics of the c++/qt libary. Did you look herebefore posting?

      Anyway, you can either use arg
      or the static QString::Number


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @J-Hilk is correct but in this specific case I would not use arg() because it localises the string (i.e. it might put in thousands separators and use local decimal separators)

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • T Offline
          T Offline
          tujiaw
          wrote on last edited by
          #4

          try:
          QStringList() << "-c" << "/usr/bin/amixer set Speaker " + QString::number(value) + "%"

          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