Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top