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. With QT C++ what are the ways to convert between an ascii integer and a string in both directions

With QT C++ what are the ways to convert between an ascii integer and a string in both directions

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 924 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.
  • A Offline
    A Offline
    AI_Messiah
    wrote on 22 May 2021, 23:21 last edited by
    #1

    I am not talking about numbers I mean the actual ascii values. I have tried to do this:

    string chr(int a)
    {
         string b;
         b = char(a);
         return b;
    }
    

    and this:

    apart = part.toStdString()[0];
    val = int(apart)
    

    I get this error:

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "private: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl MainWindow::chr(int)" (?chr@MainWindow@@AEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
    

    and

    C:\Users\damon\Documents\QT\build-markov-Desktop_Qt_6_1_1_MSVC2019_64bit-Debug\debug\markov.exe:-1: error: LNK1120: 1 unresolved externals
    

    I hate these error codes the most because they make the least amount of sense, but anyway?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 23 May 2021, 06:39 last edited by
      #2

      @AI_Messiah said in With QT C++ what are the ways to convert between an ascii integer and a string in both directions:

      unresolved external symbol

      Your chr() is defined in header file as method of MainWindow, right? But in source file, you did not define it - it should read:

      string MainWindow::chr(int a)
      

      numbers I mean the actual ascii values

      But they are the same! ASCII table is just a bunch of numbers. Anyway, if you have an ASCII code, like 'A' or 65, you can do this:

      const QString myCharacter(QChar(65));
      qDebug() << myCharacter;
      

      And to go the other way:

      qDebug() << int(myCharacter.toLatin1().at(0));;
      

      (Z(:^

      1 Reply Last reply
      1

      2/2

      23 May 2021, 06:39

      • Login

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