[英]Qt; no matching function for call
在Qt項目中遇到此錯誤;
C:\Users\Seb\Desktop\SDIcw2\shipHandler.cpp:20: error: no matching function for call to 'std::basic_ifstream<char>::open(QString&)'
infile.open(qstr);
^
發生在這個構造函數中;
SDI::shipHandler::shipHandler(std::string fileName)
{
QString qstr = QString::fromStdString(fileName.c_str());
std::string line;
std::ifstream infile;
infile.open(qstr);
while(!infile.eof())
{
getline(infile,line);
shipHandler::lineParse(line);
}
infile.close();
}
我正在通過另一個線程創建該類的初始化;
SDI::shipHandler sh("ships.txt");
只是解決了Qt上的一個問題而帶來了另一個問題。 真的為此感到煩惱,我討厭在這里發布很多內容。 只是嘗試傳遞文件名以打開文件,但在Visual Studio中工作,但移至此處以添加GUI。 非常感謝您的幫助
轉換為QString只會給您帶來問題。 如果直接使用fileName
則應該解決編譯器錯誤:
SDI::shipHandler::shipHandler(std::string fileName)
{
std::string line;
std::ifstream infile;
infile.open(fileName);
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.