Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]Unable to open resource file
QtWS25 Last Chance

[solved]Unable to open resource file

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BenBenJones
    wrote on last edited by
    #1

    Hi,

    I added a resource file "myresourcestuff.qrc" to my project "StringFinder"

    StringFinder.pro:
    @
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = StringFinder
    TEMPLATE = app
    INCLUDEPATH += .

    SOURCES += main.cpp
    stringfinder.cpp

    HEADERS += stringfinder.h

    FORMS += stringfinder.ui

    RESOURCES += myresourcestuff.qrc
    @

    and the "myresourcestuff.qrc" looks like this:
    @
    <RCC>
    <qresource prefix="/new/prefix1">
    <file>stuff.txt</file>
    </qresource>
    </RCC>
    @

    "stuff.txt" is located on the same path as the .ccp, .h, .qrc - files.

    Now I'm trying to access that file in "stringfinder.cpp"

    @
    // works
    //QFile myFile("C:/research/Qt/Qt5.2.0/Tools/QtCreator/bin/StringFinder/stuff.txt");
    // doesn't work
    QFile myFile(":/new/prefix1/stuff.txt");

    if(myFile.exists(&#41;){
        ui->textEdit->setText("opening file");
        myFile.open(QIODevice::ReadOnly);
        QTextStream textStream(&myFile);
        QString line = textStream.readAll();
        myFile.close();
    
        ui->textEdit->setPlainText(line);
    
        QTextCursor textCursor = ui->textEdit->textCursor();
        textCursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
    }
    else
    {
        ui->textEdit->setText("File not found");
    }
    

    @

    but it won't open, myFile.exists() returns "false" :/

    Can anyone help please? A minimal project is uploaded here: http://depot.tu-dortmund.de/get/ck3bx

    Best,
    Ben

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Hi BenBenJones. Welcome to devnet.
      The minimal project works ok. It is very strange that you get errors. Try "clean", "qmake", "rebuild all".

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        This should work without any problem. Just check the file extn. Some times it will somestuff.txt.tx. It may not be visible in the windows explorer. This is the only issue I suspect now.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BenBenJones
          wrote on last edited by
          #4

          Thanks, “clean”, “qmake”, “rebuild all” was the solution!!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved