PDA

View Full Version : access the network to read files



jaca
2nd March 2010, 11:01
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?

QFile file ( "\\172.27.128.41") is possible?

wysota
2nd March 2010, 11:20
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.

JohannesMunk
2nd March 2010, 12:56
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.


#include <QtCore>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QPlainTextEdit te;
te.show();

QString fileName = QFileDialog::getOpenFileName(0, "Open Text File", "", "Text Files (*.txt *.*)");
qDebug() << fileName;
QFile* f = new QFile(fileName);
if (f->open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream* ts = new QTextStream(f);
te.setPlainText(ts->readAll());
delete ts;
}
delete f;

QObject::connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));

return a.exec();
}
Debug Output:

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

HIH

Johannes

squidge
2nd March 2010, 13:00
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.