Results 1 to 4 of 4

Thread: access the network to read files

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: access the network to read files

    Why don't you just try it?

    Selecting a network file with a File-Open-Dialog and then reading it with QFile, doesn't require any special treatment.

    Windows handles SMB shares transparently.

    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QPlainTextEdit te;
    9. te.show();
    10.  
    11. QString fileName = QFileDialog::getOpenFileName(0, "Open Text File", "", "Text Files (*.txt *.*)");
    12. qDebug() << fileName;
    13. QFile* f = new QFile(fileName);
    14. if (f->open(QIODevice::ReadOnly | QIODevice::Text))
    15. {
    16. QTextStream* ts = new QTextStream(f);
    17. te.setPlainText(ts->readAll());
    18. delete ts;
    19. }
    20. delete f;
    21.  
    22. QObject::connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    23.  
    24. return a.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 
    Debug Output:

    "//JOHANNES-PC/Musik/Mexp Key.txt"

    HIH

    Johannes

  2. The following user says thank you to JohannesMunk for this useful post:

    jaca (5th March 2010)

Similar Threads

  1. how to read pc's network IP address
    By wei243 in forum Qt Programming
    Replies: 12
    Last Post: 8th January 2010, 16:59
  2. Replies: 12
    Last Post: 17th June 2009, 05:34
  3. Is QMap efficient in case of frequent read access ?
    By yellowmat in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2006, 08:20
  4. Qt4: QDir::entryList bug in windows when listing network files?
    By Yvon Halbwachs in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 14:22

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
  •  
Qt is a trademark of The Qt Company.