tags:

views:

140

answers:

2

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

+8  A: 

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.

sth
+1  A: 

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

Space_C0wb0y
And even better is not to mix STL and Qt string classes and containers.
Ton van den Heuvel
True that, but sometimes you want to hide internal datatypes of a library you use in the interfaces of your classes, to avoid clients to have to include 3rd-party headers. It's all circumstatial.
Space_C0wb0y