mac qt mysql_适用于Mac的Qt的MySQL

bd96500e110b49cbb3cd949968f18be7.png

I have wasted around 6 hours trying to get MySQL working with Qt following all sorts of instructions from the web. I want to cut my wrist off now!

Does anyone have a simple and a verbose explanation of how to install QMYSQL driver into Qt?

I have Mac 10.6 and I am a beginner n00b.

Your help will be appreciated from the bottom of my heart!

Sana.

EDIT:

I get the following files when I do the grep, so among these just for kicks I copied libqsqlmysql.dylib into all of the folders, but still I don't get to compile... I get an error saying that QSqlDatabase: QMYSQL driver not loaded

/Library/Application Support/DivX/QtPlugins/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/Assistant.app/Contents/PlugIns/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/Designer.app/Contents/PlugIns/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/Desktop/Qt/4.8.0/gcc/plugins/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/Desktop/Qt/4.8.0/gcc/plugins/sqldrivers/libqsqlite_debug.dylib

/Users/pfn368/QtSDK/Desktop/Qt/474/gcc/plugins/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/Desktop/Qt/474/gcc/plugins/sqldrivers/libqsqlite_debug.dylib

/Users/pfn368/QtSDK/Madde/sysroots/harmattan-arm-sysroot/usr/lib/qt4/plugins/sqldrivers/libqsqlite.so

/Users/pfn368/QtSDK/Madde/sysroots/harmattan-nokia-arm-sysroot/usr/lib/qt4/plugins/sqldrivers/libqsqlite.so

/Users/pfn368/QtSDK/Maemo/4.6.2/sysroots/fremantle-arm-sysroot-20.2010.36-2-slim/usr/lib/qt4/plugins/sqldrivers/libqsqlite.so

/Users/pfn368/QtSDK/Qt Creator.app/Contents/MacOS/qmlpuppet.app/Contents/PlugIns/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/Qt Creator.app/Contents/PlugIns/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/QtSources/4.8.0/plugins/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/QtSources/4.8.0/plugins/sqldrivers/libqsqlite_debug.dylib

/Users/pfn368/QtSDK/Simulator/Application/simulator.app/Contents/PlugIns/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/Simulator/Qt/gcc/plugins/sqldrivers/libqsqlite.dylib

/Users/pfn368/QtSDK/Simulator/Qt/gcc/plugins/sqldrivers/libqsqlite_debug.dylib

This is my .pro file

QT += sql core gui\

network

TARGET = mini-stock-exchange

TEMPLATE = app

SOURCES += ./src/main.cpp\

./src/mainwindow.cpp

HEADERS += ./header/mainwindow.h

FORMS += ./ui/mainwindow.ui

My includes

#include "./header/mainwindow.h"

#include "ui_mainwindow.h"

#include

#include

#include

#include

#include

#include

#include

Code to call the database

QSqlDatabase defaultDB = QSqlDatabase::addDatabase("QMYSQL3");

if ( !defaultDB.isValid() ) {

qWarning( "Failed to connect to the database driver" );

}

defaultDB.setDatabaseName( "nicu" );

defaultDB.setUserName( "root" );

defaultDB.setPassword( "root" );

defaultDB.setHostName( "http://localhost:8889" );

解决方案

The Qt 4 packages from Mac Homebrew have an option to install mysql-drivers as a Qt Plugin for default (it's not a default option, that's why you are missing this).

Download and install Mac OS X Homebrew software as described here: http://brew.sh.

After installing homebrew, remove the previously Qt4 installation.

If you have installed it using brew just type on the terminal:

$ brew remove qt4

To install it with mysql support run:

$ brew install qt4 --with-mysql

And everytime you need to install a package with some options in brew but you don't know the supported options just type:

$ brew options FORMULA_NAME

And it will show all the build options available for the given formula.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值