PDA

View Full Version : QFTP - Trying to "Put"



Bonafide
7th March 2010, 05:35
Hey guys,

I'm trying to upload a simple file to a FTP server, simply. :p

Here's what I currently have:


void PMGUI::upload()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Upload Task Log"), "", tr("TASK (*.task);;All Files (*)"));

QFile *file = new QFile (fileName);

QFtp *ftp = new QFtp();
ftp->connectToHost("ftp.******.com");
ftp->login("user", "pass");

ftp->put(file, fileName);
}


This, doesn't work (ftp address, username, and password is correct). What am I doing wrong? Also, is there a simple way to monitor the transfer progression (via QT progress bar)?

norobro
7th March 2010, 16:33
Hi Bona,

QFileDialog::getOpenFileName() returns "/path/to/fileName". You probably need to strip the path off of it.

HTH

Bonafide
7th March 2010, 17:31
How do I go about doing that?

EDIT: I used the remove() function, but I don't think that's good enough, considering if the path's length is longer than the one I specified...

EDIT 2: Currently, the new file doesn't copy the file I specified in the OpenFileDialog, what is the correct method of doing this?

norobro
7th March 2010, 18:43
I'm sure there is a more elegant way to do this, probably with QRegExp. This seems to work, although I don't really understand why:
QString fileName = QFileDialog::getOpenFileName(this, tr("Upload Task Log"), "", tr("TASK (*.task);;All Files (*)"));

QFile *file = new QFile (fileName);

QFtp *ftp = new QFtp();
ftp->connectToHost("ftp.******.com");
ftp->login("user", "pass");
QDir fileNameOnly(fileName);
ftp->put(file, fileNameOnly.dirName());


RE: your edit no 2, no comprende. I copied your code and the only change that I made was this: "ftp->put(file, "testfile.txt");" It worked fine.

Bonafide
7th March 2010, 19:09
Alright, noroboro, that works. Much more elegant than my way of doing it. Don't worry about edit two, I thought I had deleted it (I accidentally deleted edit 3). My edit 3 was asking if there a simple way of using the Qt progress bar to monitor the progression of the upload/download? Also, do you know how to make cells in a table view, non-editabled?

Thanks for all the help, once again.

norobro
7th March 2010, 20:00
You're welcome.

The qftp example (http://doc.trolltech.com/4.6-snapshot/network-qftp-ftpwindow-cpp.html) has exactly what you are looking for. Check out the slot updateDataTransferProgress()

To make all cells in a table view non editable use: setEditTriggers(QAbstractItemView::NoEditTriggers)

Bonafide
7th March 2010, 20:19
Last question (I swear!), is there a way to make text in a cell wrap so that all the text is viewable? I also noticed with the "NoEdit" trigger, it makes it impossible to read any text that doesn't directly fit into a cell. Is there a way around this?

norobro
7th March 2010, 20:48
I have no problem with your questions.I just answer with the way that I do, or would do, things. It might not always be the best way.

Try QTableView::resizeRowsToContents() or QTableView::resizeColumnsToContents()

Bonafide
7th March 2010, 21:46
No, that doesn't do it. The cell still displays the amount of characters it can, and then has the elipses at the end to indicate that there is more text. If you click on the cell, it then scrolls to the last character, though. You can scroll through the characters (left/right).

The above is impossible at all if I have the NoEdit Trigger on though. It doesn't scroll to the end.

norobro
7th March 2010, 22:18
Don't know what the problem is. Are you setting a maximum row height?

I modified the QTableView example in the docs (examples/sql/tablemodel) by changing the table displayed to offices and adding resizeRowsToContents(). Attached is a screenshot.

Bonafide
7th March 2010, 22:35
I didn't set a max height, so I'm not sure what's up. I do want to do what you did (do, do, did...) in that screenshot, though. But it's not working for whatever reason... :/

I want to go from this (below, under task), to what you have, but no matter what I do, it remains like that...
http://img411.imageshack.us/img411/5403/57468605.th.png (http://img411.imageshack.us/i/57468605.png/)

norobro
7th March 2010, 22:41
I was editing my post above while you were posting. I moved it to this post so you wouldn't miss it.

Had another thought- check your statement order. You have to set the model before calling resizeRowsToContents()

Bonafide
7th March 2010, 22:42
Yea, I had set the model before I called the resize function. So that's not it.

norobro
7th March 2010, 22:52
If you post some code, I'll see if I can spot anything.

Bonafide
7th March 2010, 22:57
Here ya go.



void PMGUI::setupView()
{
ui->taskView->setModel(model);
ui->taskView->resizeColumnToContents(5);
//QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
//ui->taskView->setSelectionModel(selectionModel);

QHeaderView *headerView = ui->taskView->horizontalHeader();
headerView->setStretchLastSection(true);

}

norobro
7th March 2010, 23:04
Don't you want to resize column no. 3?

Bonafide
7th March 2010, 23:11
I want to do it to both "Tasks" and "Notes."

norobro
7th March 2010, 23:16
Wouldn't that be cols. 3 & 4 or are you hiding columns?

As an aside: I like the look of your app but in the title don't you mean Comprehensive or maybe Komprehensive?

Bonafide
7th March 2010, 23:44
I have it at that value for now just for testing purposes; I've changed it around before. If it's not doing it to one columns, then it won't do it to the other.

Eh, I just came up with the name off the top of my head earlier today, I kinda like it. :p

norobro
7th March 2010, 23:56
After making the comment about apprehensive I looked it up.

From Merriam-Webster:
1 : capable of apprehending or quick to do so : discerning

So it fits very well. Guess my vocab is about as good as my coding:o

Looking at your table, the name, start, finish and "%" fields shouldn't ever overflow (maybe the name) so looks to me like you could use "ui->taskView->resizeColumnsToContents()" and Task and Notes would resize as necessary.

Bonafide
7th March 2010, 23:59
If I do that, I get this:

norobro
8th March 2010, 00:52
I'm at a loss without seeing more code. Did you call resizeColumnsToContents() after setRelation()? And try resizeRowsToContents().

I modified the simple relationaltablemodel example and it worked with both.

Bonafide
8th March 2010, 01:00
setRelation()? Do you mean setModel()?

There isn't much code to see regarding my table. It's controlled primarily via the Qt GUI designer.

norobro
8th March 2010, 01:29
I'm pretty much taking shots in the dark. I thought maybe you were using a relationaltablemodel and your view was showing the key. How about posting your ui_taskview.h file? Use "Manage Attachments" under additional options in advanced mode.