Results 1 to 4 of 4

Thread: access the network to read files

  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default access the network to read files

    I have two networked computers. The TCP / IP for Windows are working well. I can see the folders and files on that network by doing: Start -> Run -> \ \ 172.27.128.41
    I'd like to read these files, using Qt, directly over the network.
    Any idea how to see folders and files on the network using Qt?
    Qt Code:
    1. QFile file ( "\\172.27.128.41")
    To copy to clipboard, switch view to plain text mode 
    is possible?

  2. #2
    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: access the network to read files

    I don't think Windows allows access to remote shares using the C/C++ API, you probably have to go through WinAPI calls for the SMB protocol. You can implement a QAbstractFileEngine for it and use it with QFile then. But I don't think a ready to use solution is available right now.
    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.


  3. #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

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

    jaca (5th March 2010)

  5. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: access the network to read files

    Quote Originally Posted by jaca View Post
    I have two networked computers. The TCP / IP for Windows are working well. I can see the folders and files on that network by doing: Start -> Run -> \ \ 172.27.128.41
    I'd like to read these files, using Qt, directly over the network.
    Any idea how to see folders and files on the network using Qt?
    You can only use fully qualified UNC paths with QFile under Windows. So \\172.27.128.41 is invalid, but \\172.27.128.41\someshare\somefile is OK.

    Alternatively, you can map the share name to a drive letter.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.