Results 1 to 3 of 3

Thread: Connect - "cannot convert parameter1 from QSlider * to const QObject * "

  1. #1
    Join Date
    Aug 2012
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Connect - "cannot convert parameter1 from QSlider * to const QObject * "

    Hi everyone,

    I'm new to this forum as to C++ and now Qt. Currently I'm studying this tutorial http://doc.qt.nokia.com/4.4/tutorials-tutorial-t8.html . I hope that some of you are familiar with it?

    CODE IN TUTORIAL
    ~~~~~~~~~~~~~~~~~~~~~~~
    In the tutorial they do several connects. I believe those are relevant atm:
    • In lcdrange.cpp:
      Qt Code:
      1. connect(slider, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
      To copy to clipboard, switch view to plain text mode 
    • In main.cpp
      Qt Code:
      1. LCDRange *angle = new LCDRange;
      2. connect(angle, SIGNAL(valueChanged(int)), cannonField, SLOT(setAngle(int)));
      To copy to clipboard, switch view to plain text mode 


    So, they connect slider.valueChanged(int) with the slot cannonField.setAngle(int) "via" the signal angle.valueChanged(int).


    PROBLEM
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    I tried to connect them directly. In main.cpp I added the line
    Qt Code:
    1. connect(angle->slider, SIGNAL(valueChanged(int)), cannonField, SLOT(setAngle(int)));
    To copy to clipboard, switch view to plain text mode 

    (I also turned the QSlider * slider public in lcdrange.h)

    But then the build problem occurs "cannot convert parameter 1 from 'QSlider *' to 'const QObject *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast". I don't really understand the problem. In my view, they were connected already before, just indirect.

    I would be grateful if anybody could explain it to me, thanks!

  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: Connect - "cannot convert parameter1 from QSlider * to const QObject * "

    Sometimes compiler error messages can be rather cryptic. Add the following to your main.cpp:
    Qt Code:
    1. #include <QSlider>
    To copy to clipboard, switch view to plain text mode 
    The Clang compiler spits out a more understandable error:
    candidate function not viable: cannot convert argument of incomplete type 'QSlider *' to 'const QObject *'

  3. The following 2 users say thank you to norobro for this useful post:

    frankiefrank (24th December 2015), gebbissimo (2nd September 2012)

  4. #3
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Connect - "cannot convert parameter1 from QSlider * to const QObject * "

    This helped me so much! Thank you!

Similar Threads

  1. Replies: 2
    Last Post: 7th June 2012, 06:28
  2. Replies: 2
    Last Post: 27th January 2012, 17:29
  3. What's Up With "const QObject &"
    By wswartzendruber in forum Newbie
    Replies: 7
    Last Post: 15th October 2009, 11:53
  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. QObject::connect says "no such signal"
    By MistaPain in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2006, 05:40

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.