Results 1 to 7 of 7

Thread: Whre is the mistake?

  1. #1
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Whre is the mistake?

    I try to load (read) text file in the textEdit doing the following:

    QString myFile="data/bgen.txt";
    QFile file(myFile);
    QTextStream stream( &myFile );
    if (file.open(QFile::ReadOnly | QFile::Text))
    ui->textEdit->setPlainText(file.readAll());

    When i click the Button nothing happens.

    i add the link of the file in the resources

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Whre is the mistake?

    By default, resources are accessible in the application under the same name as they have in the source tree, with a :/ prefix. For example, the path :/images/cut.png would give access to the cut.png file, whose location in the application's source tree is images/cut.png. This can be changed using the file tag's alias attribute:
    Also, make sure your signal/slot connection is valid.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Whre is the mistake?

    the slot is done like this:
    connect(ui->pushButton_search, SIGNAL(clicked()), this, SLOT(select_dictionary()));

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Whre is the mistake?

    Check if your path to the file is correct. To verify that, use an absolute path.

  5. #5
    Join Date
    Mar 2009
    Posts
    104
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Whre is the mistake?

    i did it but it keeps to not work when i do click
    what is the role of the prefix in resources , it must be set the same as the path or not?

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Whre is the mistake?

    What is stream declared for? You are not using it.

    You are calling QFile::readAll() which returns a QByteArray that you are implicitly converting to Unicode in a QString when you set the text edit. There are possibly a couple of ways this might give you something other than what you expect: e.g. if the input file
    contains 0x0 (NUL) bytes or is already UTF8 encoded.

    Have you tried single-stepping this in your debugger?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Whre is the mistake?

    I think the main question should be whether you are trying to read data from a file in your filesystem or from a file residing in Qt resource system embedded into the application binary. The second question should be whether your slot is actually called. The latter can be verified by placing a debug statement inside the slot and seeing if it gets printed to the console when you click the button.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Whre is Qt4?
    By giusepped in forum Qt Programming
    Replies: 2
    Last Post: 3rd April 2009, 08:33
  2. how to change size of window... stupid mistake
    By Sergio_Almonte in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2007, 15:00
  3. QComboBox Assert Mistake
    By jfe in forum Qt Programming
    Replies: 8
    Last Post: 30th July 2007, 13:00
  4. Qt Quarterly mistake
    By munna in forum General Discussion
    Replies: 2
    Last Post: 20th June 2006, 19:08
  5. Bug in Qt or Qt Designer or my mistake?
    By [maTa] in forum Qt Programming
    Replies: 5
    Last Post: 9th February 2006, 00:02

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.