CobraPi
CobraPi

Reputation: 392

How to Install qt4 on macOS with homebrew?

I need to install the qt4 C++ framework for one of my classes. I tried using the regular installer from the download archives page for both qt4.7 and qt4.8, however I get the warning:

"Installing this package may damage your system, and the installation may fail."

So I looked into installing it via homebrew and initially tried:

brew tap cartr/qt4
brew tap-pin cartr/qt4
brew install qt@4

However, that gives me this error:

Error: Calling brew tap-pin user/tap is disabled! Use fully-scoped user/tap/formula naming instead.

I looked online for a solution and was able to install it by omitting the brew tap-pin cartr/qt4 command:

brew tap cartr/qt4
brew install qt@4

I then tried to create a sample qt program in the CLion IDE and checked the version I was using, and it said I was using qt5 (from the python anaconda distribution). So my question is, can I install both qt4 and qt5 on my system simultaneously? How do I select which version to use?

Upvotes: 3

Views: 3105

Answers (1)

minopret
minopret

Reputation: 4806

You can install both simultaneously. You can select which to use.

When you install qt (meaning qt5) using homebrew, it produces a "Caveats" message that answers your question.

  • It says will need to set certain environment variables yourself.
  • It says that, in only those shell sessions where you set those environment variables, qt (meaning qt5) will be available.
  • It says, if you want qt always available, then you can simply put those settings in your dot files.

If you install qt@4 and set those same variables to point to qt@4, then qt@4 will be available instead.

You can view the same "Caveats" message again using brew info qt. Here is the whole message:

qt is keg-only, which means it was not symlinked into /usr/local,
because Qt 5 has CMake issues when linked.

If you need to have qt first in your PATH run:
  echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.zshrc

For compilers to find qt you may need to set:
  export LDFLAGS="-L/usr/local/opt/qt/lib"
  export CPPFLAGS="-I/usr/local/opt/qt/include"

For pkg-config to find qt you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/qt/lib/pkgconfig"

The same commands with qt@4 made qt@4 available for me:

export PATH="/usr/local/opt/qt@4/bin:$PATH"

export LDFLAGS="-L/usr/local/opt/qt@4/lib"
export CPPFLAGS="-I/usr/local/opt/qt@4/include"

export PKG_CONFIG_PATH="/usr/local/opt/qt@4/lib/pkgconfig"

By the way, I installed qt@4 using the user/tap/formula syntax: brew install cartr/qt4/qt@4

Upvotes: 1

Related Questions