Can I use homebrew's qt5 with capybara-webkit?
Asked Answered
P

4

19

I want to use qt5's QtWebKit with capybara-webkit.

brew uninstall qt
Uninstalling /usr/local/Cellar/qt/4.8.4...
brew install qt5
This formula is keg-only: so it was not symlinked into /usr/local.
🍺  /usr/local/Cellar/qt5/5.0.2: 3103 files, 140M, built in 60.9 minutes

If I force brew to create the symlinks for qt5 I can build the native extension for capybara-webkit ..

brew link --force qt5
Linking /usr/local/Cellar/qt5/5.0.2... 122 symlinks created
gem install capybara-webkit -v '1.0.0'
Successfully installed capybara-webkit-1.0.0

.. but webkit_server crashes hard ..

bundle exec rake test:integration
Errno::EADDRNOTAVAIL: Can't assign requested address - connect(2)
dyld: Library not loaded: /private/tmp/qt5-KytU/qt-everywhere-opensource-src-5.0.2/qtwebkit/lib/QtWebKit.framework/Versions/5/QtWebKit
  Referenced from: /usr/local/opt/qt5/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets
  Reason: image not found

See full osx crash report.

I tried installing capybara-webkit with LDFLAGS and CPPFLAGS but webkit_server still crashes hard.

env LDFLAGS=-L/usr/local/opt/qt5/lib \
  CPPFLAGS=-I/usr/local/opt/qt5/include \
  gem install capybara-webkit -v '1.0.0'
Physic answered 12/6, 2013 at 21:7 Comment(2)
Did you eventually solve this issue? – Paradrop
Nah, I just gave up and kept using qt4. I don't really need any features of qt5 yet. – Physic
P
7

Two years later, the same steps from my question now work. Thanks, whoever fixed it.

gem uninstall --all capybara-webkit
brew remove qt
brew install qt5
brew linkapps qt5 # optional?
brew link --force qt5
gem install capybara-webkit

After installing qt5, I no longer see this message from my test suite:

WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt.

Uninstalling the capybara gem is not necessary (as other answers suggest) because it has no native extensions, thus no direct dependency on QT.

Physic answered 29/10, 2015 at 2:46 Comment(1)
I can confirm the brew linkapps qt5 is not necessary – Athanasia
H
28

NOTE: IAmNaN here... this answer worked find for El Cap and Yosemite but it is no longer relevant as of MacOS Sierra. Instead follow the instructions from Thoughtbot. To summarize...

  1. Download and install a new Qt from here.
  2. Edit ~/Qt5.5.1/5.5/clang_64/mkspecs/features/mac/default_pre.prf.
  3. Around line 15 find and replace -find xcrun 2 with -find xcodebuild 2.
  4. Save and run PATH=~/Qt5.5.1/5.5/clang_64/bin:$PATH gem install capybara-webkit

Now back to our regularly scheduled answer....

I got this to work on OSX Yosemite. The reason for building against Qt5 was to get some fixes not in Qt4 that prevented capybara-webkit from using font and stylesheet assets in some circumstances.

Comment out the capybara and capybara-webkit gems from your gemfile. Then:

bundle
gem uninstall capybara-webkit
gem uninstall capybara # if it complains about dependencies 'gem uninstall' them first
brew remove qt
brew remove qt5 # if you've been playing around

From a clean environment (restart your terminal):

brew tap homebrew/versions
brew install qt55
brew linkapps qt55
brew link --force qt55

Uncomment capybara and capybara-webkit in the gemfile and then:

bundle install

Note: You may safely ignore the "brew unlink" warnings issued by brew doctor.

Hom answered 13/2, 2015 at 21:42 Comment(3)
On brew link --force qt5 I got "Error: Could not symlink lib/cmake/Qt5 /usr/local/lib/cmake is not writable." So I "sudo chown [my-user] /usr/local/lib/cmake"––brew link --force qt5 worked, bundle worked and I reset ownership on that directory – Mohamedmohammad
Please note that (as stated in the official capybara-webkit installation instructions here: github.com/thoughtbot/capybara-webkit/wiki/…) qt5 will not include QtWebKit starting at version 5.6 and therefore qt 5.5 is the last version supported by the gem. This means you should replace qt5 with qt55 for each of the above install/link commands. – Brewer
I've updated the answer. Thanks for helping keep this answer current after three years @Dschee. – Hom
P
7

Two years later, the same steps from my question now work. Thanks, whoever fixed it.

gem uninstall --all capybara-webkit
brew remove qt
brew install qt5
brew linkapps qt5 # optional?
brew link --force qt5
gem install capybara-webkit

After installing qt5, I no longer see this message from my test suite:

WARNING: The next major version of capybara-webkit will require at least version 5.0 of Qt.

Uninstalling the capybara gem is not necessary (as other answers suggest) because it has no native extensions, thus no direct dependency on QT.

Physic answered 29/10, 2015 at 2:46 Comment(1)
I can confirm the brew linkapps qt5 is not necessary – Athanasia
S
4

According to https://github.com/thoughtbot/capybara-webkit/issues/885 , QT stopped working with webkit at version 5.6. However, there is a qt55 brew available, so use qt55 (instead of qt5) in the answers above.

Sensationalism answered 19/4, 2016 at 21:8 Comment(1)
Not applicable to my question from 2013, but still useful. I didn't know about the qt55 package, thanks! – Physic
T
0

I suggest to brew update, brew remove qt5 and brew install qt5, because I find on my system, that:

xcrun otool -L /usr/local/Cellar/qt5/5.0.2/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets
[snip] 
/usr/local/Cellar/qt5/5.0.2/src/qtwebkit/lib/QtWebKit.framework/Versions/5/QtWebKit (compatibility version 5.0.0, current version 5.0.2)

So Qt5 does link against QtWebKit and the link is valid on my system in contrast to yours. Therefore the suggestion to reinstall. If homebrew installs the prebuilt bottle and still has this issue, please report on Homebrew's issue tracker on github. I installed mine from source.

However, I guess an upstream issue (a minor one) is that the link points into src which should probably lib. But that is up to Qt to fix.

Therapist answered 13/6, 2013 at 14:58 Comment(3)
Thanks, I'll try a reinstall and see if otool output changes. I haven't had time yet. qt takes like 10 years to compile .. – Physic
@JaredBeck - reading this in 2015 and it's still true. Also your comment made me laugh. – Ariadne
@Ariadne yeah it's only been two years, still eight years of compiling to go ;) – Physic

© 2022 - 2024 β€” McMap. All rights reserved.