Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string has not been declared, QT

Tags:

c++

qt

I am trying to change a certain text box message. It will display my output.

This is what I have in my main()

#include "form2.h"
....
string recvMSG = "random";

182:: Form2::changeOutput(recvMSG); ...

within my form2.h I have:

#include <string.h>    
#include <iostream>
#include <stdlib.h>    
...
    void Form2::changeOutput(string s)
    {
    QString s1 = i18n(s);
    output_box.setText(s1);

    }

But i still get: .ui/form2.h:56: error: ‘string’ has not been declared

Thanks.

Edit:: kk so now its showing:: TCPClient.cpp:182: error: cannot call member function ‘virtual void Form2::changeOutput(std::string)’ without object

like image 773
NeverAgain Avatar asked Nov 27 '09 12:11

NeverAgain


2 Answers

string is in the std namespace, so you either need to refer to it as std::string, or you need to make the name available in the current scope with using namespace std; or using std::string;.

Also the header is called string, not string.h, so include it this way:

#include <string>

Generally you also might want to use QT's QString instead of std::string if you are using it in connection with QT components that usually take QString parameters.

like image 51
sth Avatar answered Nov 20 '22 19:11

sth


I guess you should use the header <string> and then use std::string (even better would be const std::string &)

like image 20
Björn Pollex Avatar answered Nov 20 '22 18:11

Björn Pollex