Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 8

0
votes
answers
47 views
+10

需要對這些文本行的意圖和對象的傳遞

0

的解釋你好可以向我解釋爲什麼在我發現在互聯網上我們使用捆綁的代碼?我們爲什麼不直接將對象放入意圖?這與執行速度有關嗎?需要對這些文本行的意圖和對象的傳遞

Contact contact = new Contact();  
Intent intent = new Intent(); 
     Bundle args = new Bundle(); 
     args.putSerializable("contact", (contact)); 
     intent.putExtra("BUNDLE", args); 

爲什麼要捆綁而不是直接這樣呢?

Intent intent = new Intent(); 
    intent.putExtra("contact", contact); 
+0

接收方期待一個包。就這樣。當然,您可以在沒有的情況下傳輸這些信但它的設計和實施都是這樣。 – greenapps

沙发
0
0

因爲intent putExtra無法直接接觸您的聯繫人。如果想要通過您的聯繫人工具Serializable接口,如下所示

public class Contact implements Serializable{ 

} 
0
votes
answers
46 views
+10

Lexik捆綁的Symfony 3

0

我用LexikAuthentication捆綁。當我嘗試使用AJAX的login_check使UI,我回來在localStorage的令牌,但是當我嘗試登錄到我的UI,我得到401 not authorizationLexik捆綁的Symfony 3

這是我login_check:

function authenticate(e) { 
     e.preventDefault(); 
     $.ajax({ 
      url: 'http://localhost:8000/login_check', 
      type: 'POST', 
      data: JSON.stringify({ 
       '_username': $('#username').val(), 
       '_password': $('#password').val() 
      }), 
      dataType: 'json', 
      contentType: "application/json", 
      access_token: "", 
      crossDomain: true, 
      success: function (data) { 
       if (data != null && data != '') { 
        var token = "Bearer " + data.token; 
        console.log(token); 
        localStorage.setItem('token', data.token); 
        } 
      } 
     }); 

任何人都知道如何解決這一問題?

沙发
0
0

好吧,我發現我自己的解決方案。 錯誤是在這裏:localStorage.setItem( '令牌',data.token); 它應該是這樣的:localStorage.setItem(「承載」 data.token);

0
votes
answers
84 views
+10

已登錄的用戶使用「FOSUser Bundle」而不先登出的「角色提升」

1

我正在使用FOSUser捆綁管理我爲我的同事在更大的Symfony項目之上創建的數據導出包的訪問我們公司的。 因此我創建了一個DataExportBundle,可以從Symfony項目中導出定義的數據部分。已登錄的用戶使用「FOSUser Bundle」而不先登出的「角色提升」

的DataexportBundle提供

  • 下載區爲我們的員工,他們可以選擇一個查詢和 在不同的格式,如JSON或CSV獲取數據。
  • 管理員可以管理(添加,編輯和刪除)員工下載區中可供選擇的數據庫查詢的管理區域。

必須保護「數據導出」下載區域,以便只有員工才能訪問它。匿名用戶不允許訪問此區域。 「數據導出」管理區域只能由一些具有額外管理角色的員工訪問。

因此,我啓用了一個角色層次在我的「security.yml」文件:

security: 
    role_hierarchy: 
     ROLE_USER:  [ROLE_USER] 
     ROLE_EDITORIAL: [ROLE_USER, ROLE_EDITORIAL] 
     ROLE_ADMIN:  [ROLE_USER, ROLE_EDITORIAL, ROLE_ADMIN] 
     ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_SUPER_ADMIN] 
    access_control: 
     - { path: ^/dataexport/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/dataexportadmin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/dataexport/, role: ROLE_EDITORIAL } 
     - { path: ^/dataexportadmin/, role: ROLE_ADMIN } 
     - { path: ^/, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    firewalls: 
     admin_secured: 
      context: site 
      pattern: ^/dataexportadmin/ 
      form_login: 
       provider: fos_userbundle 
       csrf_token_generator: security.csrf.token_manager 
       target_path_parameter: redirect_url 
       login_path: /dataexportadmin/login 
       check_path: /dataexportadmin/login_check 
      logout: 
       path: /dataexportadmin/logout 
      anonymous: true 
     main: 
      context: site 
      pattern: ^/dataexport/ 
      form_login: 
       provider: fos_userbundle 
       csrf_token_generator: security.csrf.token_manager 
       target_path_parameter: redirect_url 
       default_target_path: /dataexport/ 
       login_path: /dataexport/login 
       check_path: /dataexport/login_check 
      logout: 
       path: /dataexport/logout 
      anonymous: true 

正如你所看到的,我也定義了兩個防火牆。通過這樣做,我希望實現已登錄的具有「ROLE_EDITORIAL」角色(不具有「ROLE_ADMIN」角色)的用戶顯示的登錄表單,他可以作爲另一個用戶(必須具有「ROLE_ADMIN」角色集)。

我創建2個用戶:

sudo -u www-data bin/console fos:user:create employee_A 
sudo -u www-data bin/console fos:user:promote employee_A ROLE_EDITORIAL 

sudo -u www-data bin/console fos:user:create employee_B 
sudo -u www-data bin/console fos:user:promote employee_B ROLE_ADMIN 

我的問題是,這種「特權提升」是不行的;相反,當「employee_A」點擊指向「數據導出」管理區域的鏈接時,會顯示「403禁止訪問」頁面。我的計劃是在此處顯示登錄表單。如果登錄(並因此「特權提升」)失敗,則必須保留登錄用戶「employee_A」的角色「ROLE_EDITORIAL」。 我知道更常用的方式是用戶employee_A(ROLE_EDITORIAL)先註銷,然後以用戶employee_B(ROLE_ADMIN)登錄。這樣,捆綁包已經可以工作了,但是我想像我說的那樣實施一種「特權提升」。

我的問題是:如何使用「FOSUser bundle」或任何其他Symfony用戶管理包進行「特權提升」?

文件 「config.yml」:

fos_user: 
    db_driver: orm 
    firewall_name: main 
    user_class: AppBundleEntityFosUser 
    from_email: 
     address: ... 
     sender_name: ... 

文件 「的routing.yml」:

dataexportadmin_login: 
    path: /dataexportadmin/login 
    defaults: { _controller: MyUserBundle:Security:login } 

dataexportadmin_login_check: 
    path: /dataexportadmin/login_check 
    defaults: { _controller: MyUserBundle:Security:check } 

dataexportadmin_logout: 
    path: /dataexportadmin/logout 
    defaults: { _controller: MyUserBundle:Security:logout } 

dataexport_login: 
    path: /dataexport/login 
    defaults: { _controller: MyUserBundle:Security:login } 

dataexport_login_check: 
    path: /dataexport/login_check 
    defaults: { _controller: MyUserBundle:Security:check } 

dataexport_logout: 
    path: /dataexport/logout 
    defaults: { _controller: MyUserBundle:Security:logout } 

dataexport_admin: 
    resource: "@DataexportBundle/Controller/QueryController.php" 
    type:  annotation 
    prefix: /dataexportadmin 
    options: 
     expose: true 

dataexport: 
    resource: "@DataexportBundle/Controller/DefaultController.php" 
    type:  annotation 
    prefix: /dataexport 
    options: 
     expose: true 

my_user: 
    resource: "@MyUserBundle/Controller/" 
    type:  annotation 
    prefix: /

文件 「我/ UserBundle /控制器/ SecurityController.php」

<?php 

namespace MyUserBundleController; 

use FOSUserBundleControllerSecurityController as BaseController; 

class SecurityController extends BaseController 
{ 
    public function renderLogin(array $data) 
    { 
     $requestAttributes = $this->container->get('request_stack')->getCurrentRequest(); 

     if ($requestAttributes->get('_route') === 'dataexportadmin_login') 
     { 
      $template = sprintf('MyUserBundle:Security:adminlogin.html.twig'); 
     } 
     else 
     { 
      $template = sprintf('MyUserBundle:Security:login.html.twig'); 
     } 

     return $this->container->get('templating')->renderResponse($template, $data); 
    } 
} 

兩個Twig模板之間的相關區別是表單標記的「action」屬性:

<form action="{{ path("dataexport_login_check") }}" method="post"> 

vs.

<form action="{{ path("dataexportadmin_login_check") }}" method="post"> 

感謝您的幫助!

沙发
0
0

使用FOS用戶軟件包只有用戶是否通過身份驗證或不是。 如果您登錄另一個用戶,您將更改登錄的用戶。

你可能想改變dataexportadmin安全:

  1. 低ACCESS_CONTROL水平
  2. 路線的形式在你捆綁
  3. 如果證書檢查,在$_SESSION['allowd_to_dataexportadmin_until']
  4. 設置截止日期行動
  5. 在您的導出包中爲每個動作分派一個事件,以檢查當前用戶是否具有AUTHORISED_ROLES(admin)或非空$_SESSION['allowd_to_dataexportadmin_until']或低於new DateTime()

希望這會有所幫助

0
votes
answers
83 views
+10

FOSUserBundle窗體看起來很奇怪

0

我剛剛在我的Symfony項目上配置並準備了FOSUserBundle。但是,當我試圖表明寄存器觀點看起來像這樣:FOSUserBundle窗體看起來很奇怪

enter image description here

登記申請表(默認)應該是這樣的:

Blockquote

所有我配置的是Documentation,我不知道發生了什麼。

這是RegistrationFormType.html.twig從FOSUserBundle:

class RegistrationFormType extends AbstractType 
    { 
     ... 

     /** 
     * {@inheritdoc} 
     */ 
     public function buildForm(FormBuilderInterface $builder, array $options) 
     { 
      $builder 
       ->add('email', LegacyFormHelper::getType('SymfonyComponentFormExtensionCoreTypeEmailType'), array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle')) 
       ->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle')) 
       ->add('plainPassword', LegacyFormHelper::getType('SymfonyComponentFormExtensionCoreTypeRepeatedType'), array(
        'type' => LegacyFormHelper::getType('SymfonyComponentFormExtensionCoreTypePasswordType'), 
        'options' => array('translation_domain' => 'FOSUserBundle'), 
        'first_options' => array('label' => 'form.password'), 
        'second_options' => array('label' => 'form.password_confirmation'), 
        'invalid_message' => 'fos_user.password.mismatch', 
       )) 
      ; 
     } 
     ... 
    } 
+0

你需要看看https://symfony.com/doc/current/templating/overriding.html – zizoujab

+0

感謝您的回答,正如@ michal-g所說,我必須取消註釋該行。我之前做了壓倒一切的部分來找到這個問題。 – Mich

沙发
0
0

首先,你應該在config.yml 取消註釋行運行轉換組件


translator: { fallbacks: ["en"] }

和(就像在評論中說的)讀了關於壓倒性的意見

+0

就是這樣!它解決了我的問題。我沒有注意到該行,它的工作。謝謝Michal。 – Mich

+0

否 - 問題,但請 - 如果這anwser幫助你,標記anwser爲接受:) –

+0

當然,我剛剛接受它作爲解決方案,檢查它! ;-) – Mich

0
votes
answers
68 views
+10

如何在FOSUserBundle 2.0中定義模板引擎?

1

我剛剛從FOS User Bundle 2.0 alpha1移到了穩定版2.0,並且我得到了這個。如何在FOSUserBundle 2.0中定義模板引擎?

利用這種配置:

fos_user: 
    db_driver: orm 
    firewall_name: main 
    user_class: BizTVUserBundleEntityUser 
    from_email: 
     address: "%mailer_user%" 
     sender_name: "%mailer_user%" 
    template: 
     engine: twig 

我得到這個錯誤:

無法識別的選項 「模板」, 「fos_user」 下

而與此配置:

fos_user: 
    db_driver: orm 
    firewall_name: main 
    user_class: BizTVUserBundleEntityUser 
    from_email: 
     address: "%mailer_user%" 
     sender_name: "%mailer_user%" 
# template: 
#  engine: twig 

我反而得到這個錯誤:

必須定義參數「fos_user.template.engine」。

沙发
0
1

找到我的答案在這裏:https://github.com/FriendsOfSymfony/FOSUserBundle/issues/1621

顯然模板引擎已過時,但我稱它在我的安全控制器的自定義行。

90
votes
answers
42 views
+10

應用程序包不包含有效標識符

我嘗試運行我的項目,但我收到以下錯誤“應用程序包不包含有效的標識符。”

在這裡我的info.plist

在此輸入圖像描述

我對這個問題採取了其他答案。我的項目中沒有任何“Ressources”文件夾。

謝謝你的幫助

up vote 86 down vote accepted favorite
沙发
+860
+50

I solve this problem after I delete all build files by Xcode. Your build file path at Xcode > Preferences > Locations > Derived Data

If you didn't change the default path, Your path is like

File Path

I just deleted all files under DerivedData

等效鍵盤快捷鍵。cmd + alt + shift + k - Eager Logic 17年5月23日13:48

+40

In my case, this problem occurred when I manually removed a pod from my file browser in XCode. In order to fix it, I deleted the associated entry in my podfile, and ran 'pod install' from the terminal. Additionally, I had to delete the relevant search paths and other references to that pod. And of course I had to clean the project.

0

In my case the info.plist had the wrong encoding format, I still don't know why it changed. So I had to create a new one from Xcode and copy paste all the keys.

0

Cleaning the project solves my issue. Product -> Clean

0

I was building the wrong target on a device in my case. I was building the Test target rather than the normal app target.

0

In my case, I've added a framework into Embed Binaries phase, but it was already in my Link Frameworks and Binaries phase, which created a duplicate entry. Once I deleted one of them, this error starting appearing.

To fix it, I've removed the framework from both build phases and added it one more time

0

In my case, my app's bundle contained a dash like com.some-thing.app so I just changed it to com.something.app and the problem was fixed.

除了generatePom部分之外,在我的構建中安裝的說明包含所有內容。這似乎至關重要。 - 傑森D 2014年7月14日18:43

這是什麼意思 ?像C:/Users/XXX/WorkspaceDocx/maven/src/main/resources/myJar.jar ......或者我們可以做$ {project.basedir} /src/main/resources/myJar.jar - Igor Beaufils 2015年8月10日14:06

答案沒有提到自述文件,也沒有提到罐子。但是,如果項目帶來了罐子那麼你也可以將repo放在這裡提到的堆棧中,如下所述stackoverflow.com/a/36602256/1000011那麼你就不需要README了,因為項目就像jar一樣工作在maven中心沒有任何額外的手動步驟。 - opticyclic 2016年6月27日23:34

@opticyclic你的評論需要更多的讚成,或者這個答案需要編輯。對於那些沒有意識到安裝到本地Maven倉庫的人來說,這是一個災難的秘訣。 - Mike S 2016年7月28日18:40

Maven的安裝第三方JAR的指南 - 尼克格雷厄姆2016年11月11日19:17

8
votes
answers
44 views
+10

此應用程序無法啟動,因為它無法找到或加載Qt平台插件“cocoa”

我想我在過去的20個小時內盡我所能,但似乎沒有任何效果。我的應用程序正在運行和工作 - 就像它應該 - 我唯一的問題是我無法.app從它創建一個包。我都嘗試Py2Appcx_Freeze,但他們的非正常工作。由於多平台支持,我會堅持使用後者 - 如果可能的話。

setup.py如下所示:

import sys
from cx_Freeze import setup, Executable

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

OPTIONS = {'build_exe': {'includes': ['sip',
                                      'PyQt5',
                                      'PyQt5.QtCore',
                                      'PyQt5.QtGui',
                                      'PyQt5.QtWidgets',
                                      'PyQt5.QtMultimediaWidgets',
                                      'PyQt5.QtMultimedia',
                                      'PyQt5.QtNetwork']}}

EXECUTABLES = [Executable('main.py', base=base)]
NAME = 'coublet'
VERSION = '0.5.70'

setup(name = NAME,
      version = VERSION,
      options = OPTIONS,
      executables = EXECUTABLES)

我有的錯誤信息是這樣的:

objc[28404]: Class NotificationReceiver is implemented in both
/Users/.../build/coublet-0.5.70.app/Contents/MacOS/QtWidgets and
/usr/local/Cellar/qt5/5.3.1/lib/QtWidgets.framework/Versions/5/QtWidgets. One of
the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7fc4b96e98b0) is not the object's thread
(0x7fc4b95dbc80).
Cannot move to target thread (0x7fc4b96e98b0)

On Mac OS X, you might be loading two sets of Qt binaries into the same process.
Check that all plugins are compiled against the right Qt binaries. Export
DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
This application failed to start because it could not find or load the Qt
platform plugin "cocoa".

Available platform plugins are: cocoa, minimal, offscreen.

Reinstalling the application may fix this problem.
Abort trap: 6

我的系統信息:

Mac OS X  : 10.9.4
Python    :  3.4.1
cx_Freeze :  0.9
PyQt5:    :  5.3.1
- - -
Packages installed via: Homebrew and PIP

.app 結構體:

build/coublet-0.5.70.app
└── Contents
    ├── Frameworks
    ├── Info.plist
    ├── MacOS
    │   ├── PyQt5.QtCore.so
    │   ├── PyQt5.QtGui.so
    │   ├── PyQt5.QtMultimedia.so
    │   ├── PyQt5.QtMultimediaWidgets.so
    │   ├── PyQt5.QtNetwork.so
    │   ├── PyQt5.QtWidgets.so
    │   ├── Python
    │   ├── QtCore
    │   ├── QtCore.so
    │   ├── QtGui
    │   ├── QtGui.so
    │   ├── QtMultimedia
    │   ├── QtMultimedia.so
    │   ├── QtMultimediaWidgets
    │   ├── QtMultimediaWidgets.so
    │   ├── QtNetwork
    │   ├── QtNetwork.so
    │   ├── QtOpenGL
    │   ├── QtWidgets
    │   ├── QtWidgets.so
    │   ├── _bisect.so
    │   ├── _bz2.so
    │   ├── _codecs_cn.so
    │   ├── _codecs_hk.so
    │   ├── _codecs_iso2022.so
    │   ├── _codecs_jp.so
    │   ├── _codecs_kr.so
    │   ├── _codecs_tw.so
    │   ├── _datetime.so
    │   ├── _hashlib.so
    │   ├── _heapq.so
    │   ├── _json.so
    │   ├── _lzma.so
    │   ├── _md5.so
    │   ├── _multibytecodec.so
    │   ├── _opcode.so
    │   ├── _pickle.so
    │   ├── _posixsubprocess.so
    │   ├── _random.so
    │   ├── _scproxy.so
    │   ├── _sha1.so
    │   ├── _sha256.so
    │   ├── _sha512.so
    │   ├── _socket.so
    │   ├── _ssl.so
    │   ├── _struct.so
    │   ├── array.so
    │   ├── binascii.so
    │   ├── grp.so
    │   ├── imageformats
    │   │   ├── libqdds.dylib
    │   │   ├── libqgif.dylib
    │   │   ├── libqicns.dylib
    │   │   ├── libqico.dylib
    │   │   ├── libqjp2.dylib
    │   │   ├── libqjpeg.dylib
    │   │   ├── libqmng.dylib
    │   │   ├── libqsvg.dylib
    │   │   ├── libqtga.dylib
    │   │   ├── libqtiff.dylib
    │   │   ├── libqwbmp.dylib
    │   │   └── libqwebp.dylib
    │   ├── libcrypto.1.0.0.dylib
    │   ├── liblzma.5.dylib
    │   ├── library.zip
    │   ├── libreadline.6.dylib
    │   ├── libssl.1.0.0.dylib
    │   ├── main
    │   ├── math.so
    │   ├── platforms
    │   │   ├── libqcocoa.dylib
    │   │   ├── libqminimal.dylib
    │   │   └── libqoffscreen.dylib
    │   ├── pyexpat.so
    │   ├── readline.so
    │   ├── select.so
    │   ├── sip.so
    │   ├── termios.so
    │   ├── time.so
    │   ├── unicodedata.so
    │   └── zlib.so
    └── Resources

問題是我覺得很明顯:我做錯了什麼?(或者我不做什麼?)

沙发
+60

When building an app with cx_Freeze on MacOSX all dependent libraries (.so files on MacOSX) are packaged into the application bundle. It is this that makes the application portable to other systems, without requiring a second install of Qt.

When launching the Application, the libraries should therefore be loaded from within the bundle. However, in your case the system libraries are still being loaded:

/Users/.../build/coublet-0.5.70.app/Contents/MacOS/QtWidgets
/usr/local/Cellar/qt5/5.3.1/lib/QtWidgets.framework/Versions/5/QtWidgets

The result One of the two will be used. Which one is undefined. means that either of these could be loaded. If it picks the correct one, great! If it doesn't you've got two separate sets of libraries loading simultaneously, and that fails shortly afterwards. As an aside, you may find that if you try your Application on another system it will work fine! Sometimes.

For an overview of the problem I suggest taking a look at the following bug #33.

Before you begin

Make sure you have an up-to-date version of cx_Freeze installed. I would suggest trying to clone the repository and installing from there.

Secondly, ensure that the Qt plugins are being correctly built into your application. Cx_Freeze previously looked for the qt-menu.nib file to determine if it was building a Qt application. This is no longer available in Qt5, but you can pass it on the command-line when building your app. Set it to whatever you want, it really doesn't matter:

python setup.py bdist_mac --qt-menu-nib=/usr/local/Cellar/qt5/5.3.1/plugins/platforms/

This may be enough to fix your problem. But if not, you have two options:

Option 1

Each library file contains the paths to it's dependencies. If you're receiving this error, it means some of those paths are either a) still pointing to the original file, or b) not specific enough (and being found on your PATH or DYLD_LIBRARY_PATH). However, you can re-write paths using install_name_tool from the command line (as described here:

install_name_tool -change /usr/local/Cellar/qt5/5.3.1/lib/QtWidgets.framework/Versions/5/QtWidgets @executable_path/QtWidgets build/MyApp.app/Contents/MacOS/qt_plugins/platforms/libqcocoa.dylib
install_name_tool -change /usr/local/Cellar/qt5/5.3.1/lib/QtCore.framework/Versions/5/QtCore @executable_path/QtCore build/MyApp.app/Contents/MacOS/qt_plugins/platforms/libqcocoa.dylib
install_name_tool -change /usr/local/Cellar/qt5/5.3.1/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport @executable_path/QtPrintSupport build/MyApp.app/Contents/MacOS/qt_plugins/platforms/libqcocoa.dylib
install_name_tool -change /usr/local/Cellar/qt5/5.3.1/lib/QtGui.framework/Versions/5/QtGui @executable_path/QtGui build/MyApp.app/Contents/MacOS/qt_plugins/platforms/libqcocoa.dylib

This rewrites the paths in the libraries to point into your application folder, using @executable_path as the base. You will need to do this for all the paths that you find loading incorrectly. I'd suggest wrapping it up into an script, to run automatically after the build.

If you want to look at which libraries a file is referencing you can use otool. For example, in a successfully built application of mine:

otool -L libqcocoa.dylib 
libqcocoa.dylib:
    @executable_path/../Resources/qt_plugins/platforms/libqcocoa.dylib (compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 20.0.0) 
...

There was an updated workaround in the issue tracker that suggests that just importing the correct module in your app will get it to function, however it seems unlikely that you've made an application without QtWidgets.

Option 2

If the above doesn't work, there is another approach outlined here. This is a bit of a sledgehammer approach in that it simply prevents loading of plugins at all.

  • Add a qt.conf file next to the executable (in the .app bundle that contains:
    [Paths] Plugins = '.'

  • Either set the environment variable QT_PLUGIN_PATH="" (you can do this within your application before importing PyQt. Or call QtGui.QApplication.setLibraryPaths([]) before creating your application object.

The result is no plugins, so your application will not have access to the MacOSX Cocoa style and UI (e.g. file, colour dialogs).

很好的答案。你可以看一下這個問題:stackoverflow.com/questions/45858376 / ... - arqam於18年8月28日5:45

板凳
+20

This is in addition to @mfitzp's answer.

This QT Plugins Document came in handy.

To look for default locations that your QT app is trying to search you can use following command:

$sudo dtruss MacOS/ncher 
  getattrlist("/ncher.app", 0x7FFF954B51A4, 0x7FFF5C8FDD20)              = 0 0
  getattrlist("/ncher.app/Contents", 0x7FFF954B51A4, 0x7FFF5C8FDD20)             = 0 0
  getattrlist("/ncher.app/Contents/MacOS", 0x7FFF954B51A4, 0x7FFF5C8FDD20)               = 0 0
  stat64("/ncher.app/Contents/MacOS", 0x7FFF5C8FDED8, 0x7FFF5C8FDD20)            = 0 0
  stat64("/ncher.app/Contents/MacOS/platforms/.", 0x7FFF5C8FDF58, 0x7FFF5C8FDD20)                = -1 Err#2
  open("/dev/tty", 0x1000000, 0x1FF)             = 5 0
  fcntl(0x5, 0x2, 0x1)             = 0 0
  close(0x5)               = 0 0
  write_nocancel(0x2, "This application failed to start because it could not find or load the Qt platform plugin "cocoa".

Reinstalling the application may fix this problem.
", 0x97)              = 151 0
  sigprocmask(0x3, 0x7FFF5C8FE6B4, 0x0)            = 0x0 0
  __pthread_sigmask(0x3, 0x7FFF5C8FE6C0, 0x0)              = 0 0
  __pthread_kill(0x603, 0x6, 0x0)          = 0 0
  kevent64(0x4, 0x0, 0x0)          = -1 Err#4

You can see this QT app trying to look into MacOS/platforms, once i copied my libqcocoa.dylib plugin (its path were modified by install_name_tool command as per @mfitzp's answer) there, my application worked like charm.

BTW it is advisable by MAC codesigning guide to have this directory structure correctly setup,

DONT put Frameworks, plugins in ncher.app/Contents/MacOS directory

萬分感謝!!您的鏈接確實有幫助! - Aman 2016年1月26日10:53

你可以看一下這個問題:stackoverflow.com/questions/45858376 / ... - arqam於18年8月28日在5:47

地板
0

I had this problem in the context of just starting a Qt Widgets app from Qt Creator.

What helped me was to set the variable QT_PLUGIN_PATH to the value <Qt-dir>/plugins (where <Qt-dir> is the absolute path to the folder in the Qt directory containing, among others, bin, doc, include, lib and of course plugins).

This probably did not fix the root cause of the problem but it was a quick fix that's working fine so far.

125
votes
answers
35 views
+10

我怎麼知道Bundle中給出的數據?

我有一點時間通過Intent/ Bundles 搞清楚我的方法會有什麼數據我已經嘗試添加斷點來檢查數據,但我沒有看到任何東西。也許是因為Parcelable我無法在Eclipse中手動讀取它。

例如,a onActivityResult(int requestCode, int resultCode, Intent data)表示a Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)我如何知道可用的數據?請注意,我不是要求提供哪些數據,但我是如何理解的,所以我可以將相同的想法應用於任何Bundle/ Intent來自Android框架?也許這看起來像文檔一樣簡單,但我沒有看到完整的數據列表,我在Eclipse中看不到它。所以我迷路了。

up vote 75 down vote accepted favorite
沙发
+750
+50

Bundle.keySet() gives you a list of all keys in the bundle. That said, typically you just expect certain keys and query them, but keySet() is used to examine bundles you get from somewhere.

謝謝。我怎麼知道這個問題的期待是什麼?我現在看到它的文檔,是嗎? - user123321 2011年6月25日3:16

捆綁包實際上只是一個容器。這完全取決於打包它的應用程序。如果它是你自己的,那麼很明顯 - 它就是你輸入的內容。如果它是別人的(或來自操作系統),那麼它取決於所說的應用程序輸入的內容。選項1:檢查文檔。選項2:詢問應用程序的開發人員。選項3:使用Bundle.keySet()分析傳入的包。 - EboMike 2011年6月25日4:18

Bundle for ContactsContract.Contacts.CONTENT_URI中的東西的文檔是以startActivityForResult開頭的? - user123321 2011年6月28日4:23

它沒有在文檔中指定,因此:不要依賴它。您可以嘗試變聰明並使用Bundle.keySet在使用Google的聯繫人應用程序後查看Bundle內部的內容。但猜猜是什麼:機會是,HTC的聯繫人應用程序返回一個不同的捆綁。或MotoBlur。在您的特定情況下,您唯一可以依賴的是intent的數據,因此請閱讀此處概述的結果:stackoverflow.com/questions/866769 / ... ..您還需要除ID之外的哪些信息? - EboMike 2011年6月28日4:49

似乎不太可能根據環境返回一組不同的“標準”數據。我不關心任何特定的環境。我想知道誰知道我的任何onCallback(Intent數據)處理程序可以使用哪些數據。循環使用鍵看起來非常通用,我無法相信Google會讓開發人員自己解決問題。 - user123321 2011年6月28日4:57

+460
public static String bundle2string(Bundle bundle) {
    if (bundle == null) {
        return null;
    }
    String string = "Bundle{";
    for (String key : bundle.keySet()) {
        string += " " + key + " => " + bundle.get(key) + ";";
    }
    string += " }Bundle";
    return string;
}

像你這樣的伙伴是我如此活躍的SO給我們現成咖啡的原因:P謝謝 - khandelwaldeval 2015年1月5日12:19

+40

i getting alll key and value of bundle stored...

for (String key : bundle.keySet()) {
    string += " " + key + " => " + bundle.get(key) + ";";
}

output:

(key)       :(value)    
profile_name:abc
0

The only thing you get out of a Bundle is what you put in. Bundles are ways of passing information between activities. If you're in charge of your entire application, you shouldn't need to look inside the Bundle for your objects, you should just grab them. Think hashmap keys... if you don't know the key, it's not like you can search the hashmap.

To place an item into a Bundle and pass it on to the next activity, you need to put it as an Extra. Take a look here for an example of passing data via extras and bundles between activities.

Copied and pasted below:

From Activity1

Intent intent = new Intent(this,myActivity2.class);
Bundle bundle = new Bundle();
bundle.putString("myValue", myValue);
intent.putExtras(bundle);
navigation.this.startActivity(intent);

In Activity2

Bundle bundle = getIntent().getExtras();
act2MyValue= bundle.getString("myValue");
37
votes
answers
42 views
+10

Composer - 請求的包存在,但這些包被約束拒絕

當我從composer運行我的安裝時,我有這個錯誤:

λcomposer install您正在運行啟用了xdebug的composer。這對運行時性能有重大影響。請參閱https://getcomposer.org/xdebug 使用包信息加載composer存儲庫更新依賴項(包括require-dev)無法將您的需求解析為可安裝的軟件包集。

錯誤:

問題1 - 請求的包antoineb1 / smoney_bundle 1.0以antoineb1 / smoney_bundle [dev-master]的形式存在,但這些被約束拒絕。

我的composer.json

{
    "name": "project",
    "license": "proprietary",
    "type": "project",
    "minimum-stability": "dev",
    "prefer-stable" : true,
    "autoload": {
        "psr-4": {
            "": "src/"
        }
    },
    "config": {
        "preferred-install": "dist"
    },
    "repositories": [
        {
            "url": "bitbucket url",
            "type": "vcs"
        }
    ],
    "require": {
        "php": ">=5.5.9",
        "antoineb1/smoney_bundle": "1.0"
    }
}
沙发
+280

The version constraint "1.0" is interpreted internally as "1.0.0.0-stable" version.

But the only version available is:

antoineb1/smoney_bundle[dev-master].

So you could change the specified version to either one of the following depending on what version is suitable for you:

  • 1.0.* (which is seen by composer as >=1.0.0.0-dev <1.1.0.0-dev -- probably won't work because there obviously aren't any versions in that package)
  • dev-master
  • dev-master#<hash>
  • @dev
  • etc.

See the composer schema for reference.

我有這個問題,因為我忽略了將我的標籤推到遙控器上。它可能也值得運行composer clear-cache。 - 1981年8月23日在洛杉磯9:57

@BVengerov有沒有辦法指定一個特定的分支? - crmpicco 18年7月24日7:53

板凳
+50

The comment by @Guillaume below this answer deserves a larger presentation.

It seems that composer wants a git release that has a v in it.

So it should be v1.1.0 and not 1.1.0.

I spent about 90 minutes looking at

mikeill/my_repo 3.3.10 requires composer/installers 1.0.*@dev -> satisfiable by composer/installers[1.0.x-dev, v1.0.0, ...] but these conflict with your requirements or minimum-stability.

And a lot of github issues as well as an SO post or two before finally discovering this thread.

瑣碎而容易被忽視 - i_v_harish 18年10月3日在13:32

地板
+20

I came across this question, and found another issue, which I had completely forgotten about, which someone may find useful to have to check.

In my case I had a very old git project, which had been forked some time back, and I had to merge them together (albeit the forked project hadn't had many changes). So I identified the split point on the old project, and tagged it as version for composer, so I could use that in place of the new project.

What I had forgotten though, was that originally we didn't use composer. So the file structure at the tag point was missing composer.json. I couldn't figure out why my new tags weren't appearing on the 'exists as' list of things which were 'rejected by your contraint'. Eventually I realised I had to create a branch on the old tag, cherry-pick the commit which created the composer.json for the project, and retag that, and then it all worked.

Hopefully this will jog someones memory, if they come hunting with this error message in mind.

4楼
+20

I lost a significant amount of hair, time and sanity over this question for a while - it turned out that the problem in my case was that I was specifying a version in the composer.json within the package itself as "dev-master".

Refer to: https://getcomposer.org/doc/04-schema.md#version

Where it states:

Note: Packagist uses VCS repositories, so the statement above is very much true for Packagist as well. Specifying the version yourself will most likely end up creating problems at some point due to human error.

(emphasis mine)

I removed this version element and it worked perfectly :)

84
votes
answers
33 views
+10

來自intent的getExtra從pendingIntent啟動

在用戶從列表中選擇帶有時間的內容並在給定時間為其創建通知後,我嘗試發出一些警報。我的問題是我的意圖上的putExtra無法在廣播接收器上收到的“showame”。它總是得到空值。這是我對大部分意圖的處理方式,但我想這次可能是因為pendingIntent或者broadcastReceiver需要不同的事情。謝謝

通過掛起的意圖發送Intent的函數

public void setAlarm(String showname,String time) {

    String[] hourminute=time.split(":");
    String hour = hourminute[0];
    String minute = hourminute[1];
    Calendar rightNow = Calendar.getInstance();
    rightNow.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour));
    rightNow.set(Calendar.MINUTE, Integer.parseInt(minute));
    rightNow.set(Calendar.SECOND, 0);
    long t=rightNow.getTimeInMillis();
    long t1=System.currentTimeMillis();

    try {   

    Intent intent = new Intent(this, alarmreceiver.class);  
    Bundle c = new Bundle();            
    c.putString("showname", showname);//This is the value I want to pass
    intent.putExtras(c);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 12345, intent, 0);

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, rightNow.getTimeInMillis(),pendingIntent);
    //Log.e("ALARM", "time of millis: "+System.currentTimeMillis());
    Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();

    } catch (Exception e) {
        Log.e("ALARM", "ERROR IN CODE:"+e.toString());
    }
}

這是接收端

public class alarmreceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();      
    Bundle b = intent.getExtras();
    String showname=b.getString("showname");//This is where I suppose to receive it but its null
    NotificationManager manger = (NotificationManager) context
            .getSystemService(context.NOTIFICATION_SERVICE);

    Notification notification = new Notification(R.drawable.icon,
            "TVGuide Υπενθ?μιση", System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, tvguide.class), 0);

    notification.setLatestEventInfo(context, "Το Πρ?γραμμα Ξεκ?νησε",
            showname, contentIntent);

    notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;

    notification.sound = Uri.parse("file:///sdcard/dominating.mp3");
    notification.vibrate = new long[]{100, 250, 100, 500};
    manger.notify(1, notification);
}           
}
沙发
+510

If you change the Extra's value in the intent, then while creating the pending intent you should use the flag PendingIntent.FLAG_CANCEL_CURRENT.

A simple example would be

PendingIntent pi = PendingIntent.getBroadcast(context, 0,intentWithNewExtras,PendingIntent.FLAG_CANCEL_CURRENT);

This is the right way and will ensure that your new values are delivered.

Hope it helps.

一旦啟動了一個意圖,系統試圖重新使用它並且沒有額外的更改,這似乎不適用於具有翻板的小部件。 - Necronet 12年11月11日15:37

為我工作,我被困了幾個小時! - 阿里12年3月3日11:31

解決了2個小時的問題.... - Shajeel Afzal 2013年8月21日11:31

謝謝你的回答...... - Satheesh 13年11月26日7:52

像往常一樣訪問打算捆綁? - Chad Bingham 2014年12月8日5:06

板凳
+240

Intents are reused in the system, unless they differ on context/action I believe. Documentation Link. That is, if you have already constructed an Intent, that intent might be used later as well.

As a debug-test, you could try to add intent.setAction("" + Math.random()) below intent.putExtras(c) and see if your extras are received in the other end.

Relevant Documentation:

Because of this behavior, it is important to know when two Intents are considered to be the same for purposes of retrieving a PendingIntent. A common mistake people make is to create multiple PendingIntent objects with Intents that only vary in their "extra" contents, expecting to get a different PendingIntent each time. This does not happen. The parts of the Intent that are used for matching are the same ones defined by Intent.filterEquals. If you use two Intent objects that are equivalent as per Intent.filterEquals, then you will get the same PendingIntent for both of them.

這是正確答案......... - Necronet 12年11月11日15:38

+1,這是正確的答案,應該被接受。這真的很有用,謝謝。(順便說一句,你也可以在創建待定意圖時使用不同的請求代碼,使用哈希,這非常方便)。--Snicolas 2013年7月25日9:11

地板
+90

use different request code for different alarm notifications to avoid overwriting of same alarm time.

這是這類問題的最佳答案!解決問題的簡單而美觀的解決方法。 - Andrey Novikov 12年10月10日18:01

我同意,非常簡單的解決方法。 - jp36 12年12月18日22:43

4楼
0

You should use intent.putExtra() method. Not set bundle to extras segment. IF you set string, you whould intent.putExtra(<key>, value); Try this it will be done. I used it.

5楼
0

I was had same problem. I solved it with setting an action to intent as suggested by @aioobe here, and my intent works like a magic.

Here what i did

  ` intent.putExtra("Name", mName);
    intent.putExtra("dateTime", newdate);
    intent.setAction("" + Math.random());`

Hope it will help someone, happy coding..! :)