Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: QFTP - Trying to "Put"

  1. #1
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QFTP - Trying to "Put"

    Hey guys,

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

    Here's what I currently have:
    Qt Code:
    1. void PMGUI::upload()
    2. {
    3. QString fileName = QFileDialog::getOpenFileName(this, tr("Upload Task Log"), "", tr("TASK (*.task);;All Files (*)"));
    4.  
    5. QFile *file = new QFile (fileName);
    6.  
    7. QFtp *ftp = new QFtp();
    8. ftp->connectToHost("ftp.******.com");
    9. ftp->login("user", "pass");
    10.  
    11. ftp->put(file, fileName);
    12. }
    To copy to clipboard, switch view to plain text mode 

    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)?
    Last edited by Bonafide; 7th March 2010 at 04:41.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    Hi Bona,

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

    HTH

  3. #3
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    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?
    Last edited by Bonafide; 7th March 2010 at 16:54.

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    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:
    Qt Code:
    1. QString fileName = QFileDialog::getOpenFileName(this, tr("Upload Task Log"), "", tr("TASK (*.task);;All Files (*)"));
    2.  
    3. QFile *file = new QFile (fileName);
    4.  
    5. QFtp *ftp = new QFtp();
    6. ftp->connectToHost("ftp.******.com");
    7. ftp->login("user", "pass");
    8. QDir fileNameOnly(fileName);
    9. ftp->put(file, fileNameOnly.dirName());
    To copy to clipboard, switch view to plain text mode 

    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.

  5. The following user says thank you to norobro for this useful post:

    Bonafide (7th March 2010)

  6. #5
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    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.

  7. #6
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    You're welcome.

    The qftp example 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)

  8. The following user says thank you to norobro for this useful post:

    Bonafide (7th March 2010)

  9. #7
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    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?
    Last edited by Bonafide; 7th March 2010 at 19:33.

  10. #8
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    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()

  11. #9
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    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.

  12. #10
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    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.
    Attached Images Attached Images
    Last edited by norobro; 7th March 2010 at 21:39.

  13. #11
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    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...
    Last edited by Bonafide; 7th March 2010 at 21:40.

  14. #12
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    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()

  15. #13
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    Yea, I had set the model before I called the resize function. So that's not it.

  16. #14
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    If you post some code, I'll see if I can spot anything.

  17. #15
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    Here ya go.

    Qt Code:
    1. void PMGUI::setupView()
    2. {
    3. ui->taskView->setModel(model);
    4. ui->taskView->resizeColumnToContents(5);
    5. //QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
    6. //ui->taskView->setSelectionModel(selectionModel);
    7.  
    8. QHeaderView *headerView = ui->taskView->horizontalHeader();
    9. headerView->setStretchLastSection(true);
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

  18. #16
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    Don't you want to resize column no. 3?

  19. #17
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    I want to do it to both "Tasks" and "Notes."

  20. #18
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    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?

  21. #19
    Join Date
    Feb 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFTP - Trying to "Put"

    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.

  22. #20
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFTP - Trying to "Put"

    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

    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.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2011, 19:21
  2. Replies: 3
    Last Post: 15th February 2010, 17:27
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.