Results 1 to 18 of 18

Thread: error: invalid use of void expression

  1. #1
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default error: invalid use of void expression

    Hi guys,

    I have a little problem over here, hope you can help me. When i compile a little application i get this: error: invalid use of void expression

    I dont have any idea why im getting that message, the code that gives me problems is the following:

    Qt Code:
    1. connect(feliz, SIGNAL(clicked()), SLOT(sendImage()));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void SimpleChatClient::sendImage(){
    2. QString html;
    3. QImage img("/home/wae/Qt4/SimpleChat/SimpleChatClient/Iconos/feliz.png");
    4. chat->document()->addResource(QTextDocument::ImageResource, QUrl("/home/wae/Qt4/SimpleChat/SimpleChatClient/Iconos/feliz.png"), img);
    5. html.append("<img src=/home/wae/Qt4/SimpleChat/SimpleChatClient/Iconos/feliz.png>");
    6. socket->write("<" + nick->text().toLatin1() + "> " );
    7. socket->write(chat->setHtml(html));
    8. socket->write("\n");
    9. }
    To copy to clipboard, switch view to plain text mode 

    I also added the slot in my .h

    Hope you can help me, thank u in advanced!!!

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Could you show the declarations as well?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error: invalid use of void expression

    connect() needs 4 parameters not 3. You lost a pointer to signal receiver.

  4. #4
    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: error: invalid use of void expression

    Quote Originally Posted by Lesiok View Post
    connect() needs 4 parameters not 3. You lost a pointer to signal receiver.
    No, it doesn't. If the receiver is omitted, "this" is assumed.

    @ChineseGeek: On which line the compiler complains about?
    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.


  5. #5
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Quote Originally Posted by wysota View Post
    No, it doesn't. If the receiver is omitted, "this" is assumed.

    @ChineseGeek: On which line the compiler complains about?
    Hi, the line that gives me the error is:

    Qt Code:
    1. socket->write(chat->setHtml(html));
    To copy to clipboard, switch view to plain text mode 

    Thank u!

  6. #6
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Hi, my declaration is this:

    Qt Code:
    1. QPushButton* feliz = new QPushButton(this);
    2. chat = new QTextEdit(this);
    To copy to clipboard, switch view to plain text mode 

    And my .h is:
    Qt Code:
    1. #ifndef SIMPLECHATCLIENT_H
    2. #define SIMPLECHATCLIENT_H
    3.  
    4. #include <QWidget>
    5.  
    6. class QBuffer;
    7. class QSpinBox;
    8. class QLineEdit;
    9. class QTextEdit;
    10. class QTcpSocket;
    11.  
    12. class SimpleChatClient : public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. SimpleChatClient(QWidget* parent = 0, Qt::WFlags flags = 0);
    18. ~SimpleChatClient();
    19.  
    20. private slots:
    21. void setConnected();
    22. void setDisconnected();
    23. void toggleConnection();
    24. void sendMessage();
    25. void receiveMessage();
    26. void sendImage();
    27.  
    28. private:
    29.  
    30. QBuffer* buffer;
    31. QSpinBox* port;
    32. QLineEdit* nick;
    33. QLineEdit* server;
    34. QLineEdit* message;
    35. QTextEdit* chat;
    36. QTcpSocket* socket;
    37. QPushButton* conn;
    38. QPushButton* send;
    39. QPushButton* feliz;
    40. QPushButton* triste;
    41. QPushButton* bravo;
    42. QPushButton* sorpresa;
    43. QPushButton* llorando;
    44. QPushButton* clock;
    45. QPushButton* confundido;
    46. QPushButton* diablo;
    47. QPushButton* corazon;
    48. QPushButton* balon;
    49. QPushButton* estrella;
    50. QPushButton* enfermo;
    51. };
    52.  
    53. #endif // SIMPLECHATCLIENT_H
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Qt Code:
    1. socket->write(chat->setHtml(html));
    To copy to clipboard, switch view to plain text mode 
    tell me what do you want to write to socket with that line?
    and second question:
    what are you already writing to socket with that line?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  8. #8
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Hi, i only want to send a .png with a socket and them display that same .png on a QTextEdit.

    Thanks for your time!

  9. #9
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error: invalid use of void expression

    ok but can you tell me what exactly is that line doing? I know this but I want you to just think for a while and analize that line carefully. What is most important - what exactly you pass to socket to write?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  10. #10
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Believe me, i have thought about that line several days hehe... I think im passing a html quote to the socket and them displaying that html quote on the QTextEdit (chat)... Obviously, its wrong, otherwise i wouldnt be asking here hehe...

  11. #11
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error: invalid use of void expression

    if you don't understand why
    Qt Code:
    1. socket->write(chat->setHtml(html));
    To copy to clipboard, switch view to plain text mode 
    won't work, you need to ask yourself how a void (the result of setHtml) can be written a socket...

    The following should compile:
    Qt Code:
    1. socket->write(chat->setHtml(html)->html());
    To copy to clipboard, switch view to plain text mode 
    If that is what you want is another matter.
    It is not clear to me (or us, it seems) what you really want to do.

  12. #12
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Nop, it didnt work, now this is the error message:

    error: void value is not discarded as it should be
    error: base operand of '->' is not a pointer

  13. #13
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Quote Originally Posted by ChineseGeek View Post
    Believe me, i have thought about that line several days hehe... I think im passing a html quote to the socket and them displaying that html quote on the QTextEdit (chat)... Obviously, its wrong, otherwise i wouldnt be asking here hehe...
    No, you are passing html string to QTextEdit and result of that method (which is "void" - what you can read in documentation) you are passing to socket. So you are passing void - which is exactly nothing - to the socket. So you are writing nothing. And it is only simple C++ knowledge needed to discover that :P

    change it into those lines:
    Qt Code:
    1. chat->setHtml(html);
    2. socket->write(html);
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  14. #14
    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: error: invalid use of void expression

    Quote Originally Posted by ChineseGeek View Post
    Believe me, i have thought about that line several days hehe...
    Oh my God....

    Let's see... you are loading an image and placing its url into an html document, then setting that html on a text edit with a method returning void and wanting the result of this method to be written to a socket (look in the dictionary what the word "void" means in English) and expecting the contents to be transfered to the other end of the socket... Please tell me I'm wrong...
    Last edited by wysota; 2nd October 2009 at 19:07.
    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.


  15. #15
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default

    @faldzip:

    That didnt work neither, error:

    error: found no matching function for call ‘QTcpSocket::write(QString&)’

    @wysota:

    So, what do you recomend to do this? Or better, how can i put that image in the QTextEdit using the socket?
    Last edited by wysota; 2nd October 2009 at 23:03.

  16. #16
    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: error: invalid use of void expression

    Quote Originally Posted by ChineseGeek View Post
    So, what do you recomend to do this?
    Definitely not a method returning void. And, frankly, surely a good book about C++ and programming in general. Then also a bit of RTFM and STFW.

    Or better, how can i put that image in the QTextEdit using the socket?
    A good first step would be to browse the reference manual.
    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.


  17. #17
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error: invalid use of void expression

    Oh come on man! Im a beginner and you are a Guru, you can help me out with this!

  18. #18
    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: error: invalid use of void expression

    Quote Originally Posted by ChineseGeek View Post
    Im a beginner and you are a Guru, you can help me out with this!
    Then act as a beginner and learn the basics first before moving forward to more advanced subjects. If you don't even know what a return type of a method does how do you expect to make progress with using the API?

    I still don't know what you want to do so it is quite hard to help you. If you want to transfer this html through the socket then use QTcpSocket::write() as already told. Finding the proper transformation from the type returned by QTextEdit::html() to the type accepted by QTcpSocket::write() is your homework. It should take you no more than 20 seconds to find the appropriate method provided you start looking for it.
    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.


Similar Threads

  1. GraphicsItem is flickering
    By anafor2004 in forum Qt Programming
    Replies: 3
    Last Post: 30th September 2009, 11:44
  2. File rename detection
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 23rd July 2009, 15:22
  3. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 17:50
  4. Must construct QApplication before QPaintDevice
    By sekatsim in forum Qt Programming
    Replies: 16
    Last Post: 8th June 2008, 00:00
  5. Delayed Rendering of QTabWidget Tabs
    By mclark in forum Qt Tools
    Replies: 13
    Last Post: 14th May 2007, 22:53

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.