[英]Qt Creator Can't use const char*
I was just testing with qt creator and seem to like it as the gui of my C++. 我只是在与qt Creator进行测试,似乎喜欢它作为C ++的GUI。 Working around with some stuff and it seems that I can't use const char*!
处理一些东西,似乎我不能使用const char *!
If I add a function: 如果我添加一个功能:
header 头
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
const char* nativeStr(QString str1);
cpp CPP
const char* nativeStr(QString str1){
QByteArray ba = str1.toLocal8Bit();
return (const char*)ba.data();
}
I get the error (when debugging): 我收到错误消息(调试时):
LNK2019: unresolved external symbol "public: char const * -_thiscall MainWindow::nativeStr(class QString)" 9?nativeStr @MainWindow@@QAEPBDVQString@@@z) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AAEXXZ)
File not found: mainwindow.obj
Help? 救命? I have no idea and I've only used win32 C++ before.
我不知道,我以前只用过win32 C ++。
I've also tried: build->clean all build->run qmake 我也尝试过:构建->清理所有构建->运行qmake
You're missing the MainWindow::
part of the function name: 您缺少函数名称的
MainWindow::
部分:
const char* MainWindow::nativeStr(QString str1){
QByteArray ba = str1.toLocal8Bit();
return (const char*)ba.data();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.