简体   繁体   English

Qt的; 没有匹配的通话功能

[英]Qt; no matching function for call

Getting this error in a Qt project; 在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);
                     ^

Happening in this constructor; 发生在这个构造函数中;

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();
}

I'm creating initializing the class in another thread by; 我正在通过另一个线程创建该类的初始化;

SDI::shipHandler sh("ships.txt");

Only just solved a problem on Qt and its brought about another problem. 只是解决了Qt上的一个问题而带来了另一个问题。 Really getting annoyed with this and I hate posting a lot on here. 真的为此感到烦恼,我讨厌在这里发布很多内容。 Simply trying to pass the file name to open, worked in visual studio but moving here to add the gui. 只是尝试传递文件名以打开文件,但在Visual Studio中工作,但移至此处以添加GUI。 Help is GREATLY appreciated 非常感谢您的帮助

Converting to the QString is just causing you problems. 转换为QString只会给您带来问题。 The compiler error should be solved if you just use fileName directly: 如果直接使用fileName则应该解决编译器错误:

SDI::shipHandler::shipHandler(std::string fileName)
{
    std::string line;
    std::ifstream infile;
    infile.open(fileName);
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM